0
無法從數據透視表獲得列數據這些都是我的模型獲取數據
產品
public function users()
{
return $this
->belongsToMany('App\User')
->withTimestamps()
->withPivot('auth_product');
}
用戶
public function products()
{
return $this
->belongsToMany('App\Products')
->withTimestamps()
->withPivot('auth_product');
}
控制器
$authorized_users = Products::find($id)->pivot->auth_user;
它給「嘗試獲得非客體的財產「。我試圖讓布爾值
編輯:Succeded中獲取價值,但現在給「空」值
$authorized_users = Products::find($id)->first()->pivot['auth_user'];
它給空,但有值下的product_id(用作外鍵)該列,但它仍然拋出空 – OunknownO