简体   繁体   English

Laravel Eloquent ORM:访问表的特定单元格

[英]Laravel Eloquent ORM: Accessing a specific cell of table

I am trying to access a specific cell of a table. 我正在尝试访问表的特定单元格。 I have to run the following query in Laravel Eloquent ORM: 我必须在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 HomeController.php第52行中的ErrorException:未定义的属性: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. ->get()返回一个集合, ->first()返回一个模型。

Either replace ->get() with ->first() , or do $user->first()->email . ->first()替换->get() ,或执行$user->first()->email

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM