-
app/Traits/ExposePermissions.php
Open in GitHubuse Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Support\Str; trait ExposePermissions { protected function can(): Attribute { $model = $this; return Attribute::make( get: static function() use ($model) { return collect($model::PERMISSIONS) ->mapWithKeys(static fn($item) => [ $item => request()->user()->can(Str::camel($item), $model) ]); } )->shouldCache(); } }
-
app/Models/Task.php
Open in GitHubuse App\Traits\ExposePermissions; use Illuminate\Database\Eloquent\Model; class Task extends Model { use SoftDeletes; use ExposePermissions; use HasFactory; // ... }
-
app/Models/Project.php
Open in GitHubuse App\Traits\ExposePermissions; use Illuminate\Database\Eloquent\Model; class Project extends Model { use SoftDeletes; use ExposePermissions; use HasFactory; // ... }