Download the PHP package berthott/laravel-api-permissions without Composer
On this page you can find all versions of the php package berthott/laravel-api-permissions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download berthott/laravel-api-permissions
More information about berthott/laravel-api-permissions
Files in berthott/laravel-api-permissions
Package laravel-api-permissions
Short Description Laravel Helper for API Endpoint Permissions
License MIT
Informations about the package laravel-api-permissions
Laravel-API-Permissions
A helper for API Permissions in Laravel. Protect all your routes with a single middleware.
Installation
Usage
- Caution: This package assumes, that you name all your routes in the way laravel does:
models.action
. - Add the
permissions
middleware to the routes you want to protect. -
Seed the permissions table by writing your own Seeder:
php artisan make:seeder PermissionTableSeeder
- utilize
berthott\Permissions\Helpers\PermissionsHelper
to actually seed the permissions PermissionsHelper::resetTables()
will truncate all permission related tables.-
PermissionsHelper::buildRoutePermissions()
will build the permissions table. You might pass an array for mapping routes to permissions. E.g. PermissionsHelper::buildUiPermissions()
will add UI permissions, that will only be handle by the frontend.
- If the
migrate
option istrue
the package will migrate five tables for you:roles
,role_user
,permissions
,permissionables
andpermission_routes
. -
If the
migrate
option isfalse
and you want to write your own migration you can have look at the default migrations by running - You can add
permissions
to yourUser
model by adding theHasPermissions
trait. - You can add
roles
to youUser
model by adding theHasRoles
trait. - You can use either or both of the above options.
- You may ignore specific routes actions from the permission system by adding them to the
ignoreActions
config, or by added theIgnorePermissionRoutes
trait.
Options
To change the default options use
- Inherited from laravel-targetable
namespace
: String or array with one ore multiple namespaces that should be monitored for the configured trait. Defaults toApp\Models
.namespace_mode
: Defines the search mode for the namespaces.ClassFinder::STANDARD_MODE
will only find the exact matching namespace,ClassFinder::RECURSIVE_MODE
will find all subnamespaces. Defaults toClassFinder::RECURSIVE_MODE
.prefix
: Defines the route prefix. Defaults toapi
.
- General Package Configuration
middleware
: An array of all middlewares to be applied to all of the generated routes. Defaults to[]
.ignoreActions
: Defines an array of actions that should be ignored by default. Defaults to[]
.migrate
: Defines wether or not to migrate standard tables.. Defaults totrue
.
Compatibility
Tested with Laravel 10.x.
License
See License File. Copyright © 2023 Jan Bladt.