2016-09-05 251 views

回答

1

relationships docs看看:

$article = Article::where('id','=',10)->with('user')->first(); 

echo "article {$article->id} by {$article->user->name}"; 
0

您需要的關係方法添加到您的Article型號:

public function user() 
{ 
    return $this->belongsTo(User::class, 'user_id'); 
} 

然後,你可以通過一個神奇的方法可以訪問該用戶user屬性如下:

{{ $article->user->email }}