$picture = User::find(Session::get('user_id'))
->pictures()->where('approved', '=', '1')->first();
如何根据用户名修改此代码而不是Session :: get(' user_id')
感谢。
答案 0 :(得分:1)
如果用户已登录,请尝试
$pictures = Auth::user()->pictures()->where('approved', '1')->first();
<强>更新强>
关于你的评论:
try {
$pictures = User::where('name', $searchname)->firstOrFail()->pictures()->where('approved', '1')->first();
}
catch (Exception $e) {
// stuff to do, if no user is found
}