hasAccess('admin')) { return true; } /** * If we got here by $this→authorize('something', $actualModel) then we can continue on Il but if we got here * via $this→authorize('something', Model::class) then calling Company:: isCurrentUserHasAccess($item) gets weird. * Bail out here by returning "nothing" and allow the relevant method lower in this class to be called and handle authorization. */ if (!$item instanceof Model){ return; } /** * The Company::isCurrentUserHasAccess() method from the company model handles the check for FMCS already so we * don't have to do that here. */ if (!Company::isCurrentUserHasAccess($item)) { return false; } } /** * These methods handle the generic view/create/edit/delete permissions for the model. * * @param User $user * @return bool */ public function index(User $user) { return $user->hasAccess($this->columnName().'.view'); } /** * Determine whether the user can view the accessory. * * @param \App\Models\User $user * @return mixed */ public function view(User $user, $item = null) { return $user->hasAccess($this->columnName().'.view'); } public function files(User $user, $item = null) { return $user->hasAccess($this->columnName().'.files'); } /** * Determine whether the user can create accessories. * * @param \App\Models\User $user * @return mixed */ public function create(User $user) { return $user->hasAccess($this->columnName().'.create'); } /** * Determine whether the user can update the accessory. * * @param \App\Models\User $user * @return mixed */ public function update(User $user, $item = null) { return $user->hasAccess($this->columnName().'.edit'); } /** * Determine whether the user can update the accessory. * * @param \App\Models\User $user * @return mixed */ public function checkout(User $user, $item = null) { return $user->hasAccess($this->columnName().'.checkout'); } /** * Determine whether the user can delete the accessory. * * @param \App\Models\User $user * @return mixed */ public function delete(User $user, $item = null) { $itemConditional = true; if ($item) { $itemConditional = empty($item->deleted_at); } return $itemConditional && $user->hasAccess($this->columnName().'.delete'); } /** * Determine whether the user can manage the accessory. * * @param \App\Models\User $user * @return mixed */ public function manage(User $user, $item = null) { return $user->hasAccess($this->columnName().'.edit'); } }