简体   繁体   中英

CRUD help laravel 5.8 user

its my firstime using laravel, now i at the auth, i make a user view and controller for add new user trough view its alrd solved and bcrypt password but every time i update through view, this password changed to str in database

public function create(Request $request)
{
    $user = new \App\User;
    $user->name = $request->name;
    $user->role = $request->role;
    $user->email = $request->email;
    $user->password = bcrypt('$request->password');
    $user->remember_token = str_random(60);
    $user->save();

    return redirect('/user')->with('success','Success data update');
}

            public function update(Request $request,$id)
         {
    $user = \App\User::find($id);
    $user->update($request->all());
    return redirect('/user')->with('succses','Succsess data update');
}

this is my create controller and update in same UserController.php

You shouldn't put a variable between single quotes. It'll interpret it always a string .

public function create(Request $request)
{
    $user = new \App\User;
    $user->name = $request->name;
    $user->role = $request->role;
    $user->email = $request->email;
    $user->password = bcrypt($request->password);
    $user->remember_token = str_random(60);
    $user->save();

    return redirect('/user')->with('success','Success data update');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM