Looking to hire Laravel developers? Try LaraJobs

laravel-policy-abilities-export maintained by mathewparet

Description
Export Laravel Policy abilities to JSON for use with VueJS front end
Author
Last update
2023/08/07 14:23 (dev-master)
License
Downloads
1 137

Comments
comments powered by Disqus

mathewparet/LaravelPolicyAbilitiesExport

This package exports all laravel policy defined abilities as a JSON object for VueJS to process.

Installation

Require the module:

composer require mathewparet/laravel-policy-abilities-export

Add the ExportsPermissions trait to your model

use mathewparet\LaravelPolicyAbilitiesExport\Traits\ExportsPermissions;
// ...
class Blog extends Model
{
    use ExportsPermissions;
}

Usage

The model will now have a can attribute that lists all abilities for that record.

For global abilities that are tied to the model but not the record itself (E.g., Blog Create), call Model::globalAbilities()

To create a resource collection that would export global abilities along with it, run:

php artisan make:resource-collection [--model=MODEL] name