リレーション先の取得
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 を全て取り出す。