此问题已在此处有答案:
Laravel current user in model(2个答案)
Laravel: Auth::user()->id trying to get a property of a non-object(23个回答)
Laravel 5 want to access auth user id in model(6个答案)
14小时前关闭
如何从模型中获取auth
用户
class Conversation extends Model
{
use HasFactory;
protected $fillable = [
'user1_id',
'user2_id',
'last_message_id'
];
public function lastMessage() : BelongsTo {
//
}
public function user() :BelongsTo {
//
}
}
同样,我想从与用户的对话中获取接收者用户的详细信息,以便传递给视图
1条答案
按热度按时间xxls0lw81#
获取当前身份验证用户User
auth()->user()
或Auth::user
这对我很有效干杯