我的Laravel有一种奇怪的行为.
一切都工作得很好,但后来我决定将col名称"user_id"更改为"seller_id"
而且我也正确地更改了控制器中的列名称
public function transactions(){
return $this->hasMany('App\Transaction', 'seller');
}
Run Code Online (Sandbox Code Playgroud)
然后我成功登录,并在一个视图中有这一行:
auth()->user->id
Run Code Online (Sandbox Code Playgroud)
返回我的错误:
"Undefined property:Illuminate\Auth\AuthManager :: $ user
我在互联网上看到我没有登录的错误和接缝,但我,任何线索?
谢谢
您指出的错误与您的更改无关.
您可以在此处参考文档,以检索您可以调用的经过身份验证的用户:
// Get the currently authenticated user...
$user = Auth::user();
Run Code Online (Sandbox Code Playgroud)
要么
// Using helper function
$user = auth()->user()
Run Code Online (Sandbox Code Playgroud)
因此,要检索用户的ID:
$id = Auth::id();
Run Code Online (Sandbox Code Playgroud)
要么
$id = auth()->id();
Run Code Online (Sandbox Code Playgroud)
要么
$id = Auth::user()->id;
Run Code Online (Sandbox Code Playgroud)
要么
$id = auth()->user()->id;
Run Code Online (Sandbox Code Playgroud)
此外,您需要根据文档更改关系函数:
public function transactions(){
return $this->hasMany('App\Transactions', 'seller_id');
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
184 次 |
| 最近记录: |