public function devices() { if ($this->hasGlobalRead()) { $instance = $this->newRelatedInstance('App\Models\Device'); return new HasAll($instance); } else { return $this->belongsToMany('App\Models\Device', 'devices_perms', 'user_id', 'device_id'); } }