我有两个型号:
Place::find(1)->users[0]->pivot->type
我添加了这个方法,但它不起作用并返回字符串:
public function getTypeAttribute($value){
return collect(json_decode($value));
}
我忘记使用
using
。应该是这样的:
$this->belongsToMany(Place::class, 'roles', 'place_id', 'user_id')->using(Role::class)->withPivot('type');