1
votes

I am using hashing algorithm using Laravel Hashing.

But got this error

Undefined property: Illuminate\Database\Eloquent\Builder::$password

Here is my function

public function signin(LoginFormValidation $request)
{
    $user_password = $request->password;

    $data = User::where('email','=',$request->email); 

    if (Hash::check($user_password, $data->password, flase))
    {
        echo "success";
    }
    else
    {
        echo "still not";
    }
}
4
It is not flase it is false, and you should use first() or get()Eazy Sam

4 Answers

2
votes

Change this line:

$data = User::where('email','=',$request->email);

To

$data = User::where('email','=',$request->email)->first();

And change:

if (Hash::check($user_password, $data->password, flase))

To

if (Hash::check($user_password, optional($data)->password))
0
votes

try this

public function signin(Request $request)  //chnaged object to Request
{
    $user_password = $request->password;

    $data = User::where('email',$request->email)->first();  // Added first()

    if ($data  && Hash::check($user_password, $data->password, false)) // typo error false
    {
        echo "success";
    }
    else
    {
        echo "still not";
    }
}
0
votes

Make your code better, I have added a fix and an additional chek in your IF statement. This additional check is required for the case where $data does not obtain a valid result.

public function signin(LoginFormValidation $request)
{
    $user_password = $request->password;

    $data = User::where('email','=',$request->email)->first(); 

    if ($data && Hash::check($user_password, $data->password))
    {
        echo "success";
    }
    else
    {
        echo "still not";
    }
}
0
votes

Can I see your model User ? I think you should remove password from protected $hidden properties then try again. Let me know if you make it