dimanche 29 novembre 2015

Laravel Validation Passing Blank Input

I have a laravel form to update existing user's information in the database, but if a field in that form is blank, I don't want it to update that record in the database. As it is now, if the field is blank and the form is submitted, it passes that blank input and removes the record in the database.

Below is the function to edit the user's information and then perform the database update. I currently attach the Request::old('...') to the email, but since the validation on that is 'unique:users', it gives the error 'email is taken'.

Thanks,

public function postEdit(Request $request)
{
    $this->validate($request, [
        'email' => 'unique:users|email|max:255',
        'password' => 'min:6',
        'confirm_password' => 'same:password', 
        'about_me' => 'max:500',
    ]);

    Auth::user()->update([


        'email' => $request->input('email'),
        'password' => bcrypt($request->input('password')),
        'confirm_password' => bcrypt($request->input('confirm_password')),
        'about_me' => $request->input('about_me'),
    ]);

    return redirect()->route('profile.edit')->with('info', 'You have updated your profile!');
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire