我想获取所有具有admin用户的设备列表。我有device_user表。但是我没有任何带有管理员ID的行。我不想通过数据库将任何设备分配给管理员。我已经尝试过了。
public function devices(){
if (Gate::allows('isUser')) {
return $this->belongsToMany('App\Device','device_user','user_id','device_id');
}elseif(Gate::allows('isAdmin')){
return Device::all();
}
}
$data['list_devices'] = User::where('id', $id)->with('devices')->first();
$list = [];
foreach ($data['list_devices']->devices as $element) {
$list[] = $element->last_information_id;
}