LoginSignup
1
0

More than 5 years have passed since last update.

Laravel シチュエーション別対応方法

Posted at

1対多で1のデータの1カラムを取得したい

  • 多のModelでbelongsToを定義してやり、取得する
$model = Sample::find(1);
$userName = $model->account[User::USER_NAME];
  • リレーション
public function user()
{
    return $this->belongsTo(
        User::class,
        User::USER_ID,
        Sample::USER_ID
    );
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0