*/ public function directives(): array { return [ ...parent::directives(), ...($this->isTrashable() ? ['softDeletes' => []] : []), ...$this->canModelDirective(), ]; } /** * Build the canModel directive for authorization. * * @return array */ protected function canModelDirective(): array { return [ 'canModel' => [ 'ability' => 'viewAny', 'injectArgs' => 'true', 'model' => $this->model(), ], ]; } /** * Get the model related to the query. * * @return class-string * * @throws Exception */ public function model(): string { $baseType = $this->baseType(); if ($baseType instanceof EloquentType) { return $baseType->model(); } throw new Exception("The base return type must be an instance of EloquentType, " . get_class($baseType) . " given."); } /** * Determine if the return model is trashable. * * @return bool */ protected function isTrashable(): bool { $baseType = $this->baseType(); if ($baseType instanceof EloquentType && $baseType instanceof HasFields) { return in_array(new DeletedAtField(), $baseType->fields()); } return false; } }