Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

cattr-app/server-application

87 stars
3 code files
View cattr-app/server-application on GitHub

app/Traits/ExposePermissions.php

Open in GitHub
use 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 GitHub
use App\Traits\ExposePermissions;
use Illuminate\Database\Eloquent\Model;
 
class Task extends Model
{
use SoftDeletes;
use ExposePermissions;
use HasFactory;
 
// ...
}

app/Models/Project.php

Open in GitHub
use App\Traits\ExposePermissions;
use Illuminate\Database\Eloquent\Model;
 
class Project extends Model
{
use SoftDeletes;
use ExposePermissions;
use HasFactory;
 
// ...
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.