I have this basic query i want to perform but an error keeps coming up. Probably due to my newness to laravel.
here is the code:
$userRecord = $this->where('email', $email)->where('password', $password); echo "first name: " . $userRecord->email;
I am trying to get the user record matching the credentials where email AND password are a match. This is throwing an error:
Undefined property: Illuminate\Database\Eloquent\Builder::$email
I've checked the email and password being passed to the function, and they are holding values. what is the problem here?
Thanks,
$this->where('email', $email)->where('password', $password)
is returning a Builder object which you could use to append more where filters etc.
To get the result you need:
$userRecord = $this->where('email', $email)->where('password', $password)->first();
You either need to use first()
or get()
to fetch the results :
$userRecord = $this->where('email', $email)->where('password', $password)->first();
You most likely need to use first()
as you want only one result returned.
If the record isn't found null
will be returned. If you are building this query from inside an Eloquent class you could use self
.
for example :
$userRecord = self::where('email', $email)->where('password', $password)->first();
More info here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With