0
0

More than 3 years have passed since last update.

リレーション先の要素のレコードを取得する

Last updated at Posted at 2020-12-02

リレーション先の取得

Model.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;

class Work extends Model
{
    protected $fillable = ['name','title','description',];

    public function artist()
    {
        return $this->belongsTo(Artist::class);
    }

    //そのユーザーが所有するアーティスト達を取得し、アーティスト達の user_id を全て取り出す。
        public function work_artist_userid()
    { 
        $artists = $this->artist()->get();
        foreach ($artists as $artist){

        return $artist->user_id; 
        }
    }
}

そのユーザーが所有するアーティスト達を取得し、アーティスト達の user_id を全て取り出す。

0
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
0
0