jeudi 14 octobre 2021

how do i ingoer inputs that dosn't have a data in update method

i have a form to update user data name and email and username the qustion is if user want to update only user how i keep same email and name or change only name in my case the valdetion required all inputs this is my controller

 public function update(Request $request, $username )
{
    if($username != Auth::user()->username){
        return abort('401');
    }

    $request->validate([

        'name' => 'min:10|max:50|required',
        'username' => 'unique:users|max:30|min:3|required',
        'email' => 'email|unique:users|max:200|required',

    ]);
    $checkuserindb = User::findOrFail(Auth::user()->id);

        $checkuserindb->update([
            'name' => $request->name,
            'username' => $request->username,
            'email' => $request->email
        ]);
        return redirect()->route('userProfile', $request->username)->with('message', 'your account has been updated!');



}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire