I am trying to access a specific cell of a table. I have to run the following query in Laravel Eloquent ORM:
SELECT email FROM users WHERE id=$id;
Here is what I have done so far:
$user=new users;//users is model
$user=users::where('email',$email)
->where('password',$pass)
->get();
$mail=$user->email;
And I encounter this error:
ErrorException in HomeController.php line 52: Undefined property: Illuminate\\Database\\Eloquent\\Collection::$email
Any help?
Figured I'd put this up as answer for anyone else that comes looking -
->get()
returns a collection, ->first()
returns a model.
Either replace ->get()
with ->first()
, or do $user->first()->email
.
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.