mercredi 15 août 2018

Hashing a fillable password

I have no idea how to hash fillable password input. I'm trying to hash it then gets stored to the database. Here's what I've done so far

use App\User;
use Illuminate\Http\Request;

class RegistrationController extends Controller
{
  public function store()
  {
      $this->validate(request(), [
          'name' => 'required',
          'email' => 'required|email',
          'password' => 'required|confirmed'
      ]);

      $pass = bcrypt(request()->password);
      $user = User::create(request(['name', 'email', $pass]));

      auth()->login($user);
    return redirect()->home();
  }
}
class User extends Authenticatable
{
    use Notifiable;

    protected $fillable = [
        'name', 'email', 'password'
    ];

    protected $hidden = [
        'password', 'remember_token',
    ];
}

It gives me a QueryException: SQLSTATE[HY000]: General error: 1364 Field 'password' doesn't have a default value (SQL: insert into users (name, email, updated_at, created_at) values (the name i inserted, email inserted, date timestamp, date timestamp)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire