[英]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.