lundi 28 septembre 2020

How to store Hashed Password to the Database using Laravel 5.8

I need to store Password as hashed to the database, I was able to has the password but when I submit my form the password stores as un-hashed,

Here's my controller Store Function

 public function store(Request $request)
{

    $hash = ['password' => Hash::make($request)];

    //dd($hash);
    // HASHED PASSWORD WAS DISPLAYED HERE 


    $user = User::create($this->validateRequest());

    dd('User Created');
}

Here's my Validate Function

private function validateRequest()
{

    return request()->validate([
        'name' => ['required', 'string', 'max:255'],
        'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
        'password' => ['required', 'string', 'min:8', 'confirmed'],
        'phone' => 'required',
    ]);
}

I tried to do this in my Store Function (But it didn't work !!)

public function store(Request $request)
    {

        $hash = ['password' => Hash::make($request)];

        $user = User::create($this->validateRequest($hash));
        dd('User Created');
   }

Is there a way where I can store the hashed password to the DB by this way ?

Or else do I need to stick to this way ;( ?

$user = User::create([
            'name' => $request['name'],
            'phone' => $request['phone'],
            'email' => $request['email'],
            'password' => Hash::make($request['password']),
        ]);

I just wanted my controllers to be clean with few lines of code.

Can someone please help me out.

Thanks



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2EFuwO2
via IFTTT

Aucun commentaire:

Enregistrer un commentaire