繁体   English   中英

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

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

我正在尝试访问表的特定单元格。 我必须在Laravel Eloquent ORM中运行以下查询:

SELECT email FROM users WHERE id=$id;

到目前为止,这是我所做的:

$user=new users;//users is model
$user=users::where('email',$email)
   ->where('password',$pass)
   ->get();
$mail=$user->email;

我遇到这个错误:

HomeController.php第52行中的ErrorException:未定义的属性:Illuminate \\ Database \\ Eloquent \\ Collection :: $ email

有什么帮助吗?

想通了,我想把它作为其他任何人的答案-

->get()返回一个集合, ->first()返回一个模型。

->first()替换->get() ,或执行$user->first()->email

暂无
暂无

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

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