記事(article)をリレーションしてユーザ(user)を取り出す例です。
モデルでbelongsToを設定
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
/**
* モデルと関連しているテーブル
*
* @var string
*/
protected $table = 'article';
protected $fillable = ["title"];
//belongsTo設定
public function user()
{
return $this->belongsTo('App\User');
}
}
html内で次で呼べるようだ。
{{$article->user->name}}
参考サイト