diff --git a/src/Resources/Resource.php b/src/Resources/Resource.php index c3363239..80d3a691 100644 --- a/src/Resources/Resource.php +++ b/src/Resources/Resource.php @@ -171,6 +171,36 @@ public function getPolicy(): mixed return Gate::getPolicyFor($this->getModel()); } + /** + * Map the resource abilities. + */ + public function mapAbilities(): array + { + return [ + 'viewAny' => function (Request $request): bool { + return is_null($this->getPolicy()) || Gate::allows('viewAny', $this->getModel()); + }, + 'create' => function (Request $request): bool { + return is_null($this->getPolicy()) || Gate::allows('create', $this->getModel()); + }, + 'view' => function (Request $request, Model $model): bool { + return is_null($this->getPolicy()) || Gate::allows('view', $model); + }, + 'update' => function (Request $request, Model $model): bool { + return is_null($this->getPolicy()) || Gate::allows('update', $model); + }, + 'delete' => function (Request $request, Model $model): bool { + return is_null($this->getPolicy()) || Gate::allows('delete', $model); + }, + 'forceDelete' => function (Request $request, Model $model): bool { + return is_null($this->getPolicy()) || Gate::allows('delete', $model); + }, + 'restore' => function (Request $request, Model $model): bool { + return is_null($this->getPolicy()) || Gate::allows('delete', $model); + }, + ]; + } + /** * Set the relations to eagerload. */ diff --git a/src/Traits/MapsAbilities.php b/src/Traits/MapsAbilities.php index 272e1e6b..4b933490 100644 --- a/src/Traits/MapsAbilities.php +++ b/src/Traits/MapsAbilities.php @@ -2,39 +2,15 @@ namespace Cone\Root\Traits; -use Illuminate\Database\Eloquent\Model; -use Illuminate\Http\Request; -use Illuminate\Support\Facades\Gate; - trait MapsAbilities { - /** + /** * Map the resource abilities. */ public function mapAbilities(): array { return [ - 'viewAny' => function (Request $request): bool { - return is_null($this->getPolicy()) || Gate::allows('viewAny', $this->getModel()); - }, - 'create' => function (Request $request): bool { - return is_null($this->getPolicy()) || Gate::allows('create', $this->getModel()); - }, - 'view' => function (Request $request, Model $model): bool { - return is_null($this->getPolicy()) || Gate::allows('view', $model); - }, - 'update' => function (Request $request, Model $model): bool { - return is_null($this->getPolicy()) || Gate::allows('update', $model); - }, - 'delete' => function (Request $request, Model $model): bool { - return is_null($this->getPolicy()) || Gate::allows('delete', $model); - }, - 'forceDelete' => function (Request $request, Model $model): bool { - return is_null($this->getPolicy()) || Gate::allows('delete', $model); - }, - 'restore' => function (Request $request, Model $model): bool { - return is_null($this->getPolicy()) || Gate::allows('delete', $model); - }, + // ]; } }