codexshaper / laravel-permission
Laravel Multiple Authentication
Installs: 327
Dependents: 0
Suggesters: 0
Security: 0
Stars: 20
Watchers: 3
Forks: 7
Open Issues: 23
- dev-master
- v1.7
- v1.6
- v1.5
- v1.4
- v1.3
- v1.2
- v1.1
- v1.0
- v0.9
- v0.8
- v0.6
- v0.5
- v0.4
- v0.3
- v0.2
- v0.1
- dev-dependabot/npm_and_yarn/minimist-and-mkdirp-1.2.8
- dev-dependabot/npm_and_yarn/json5-1.0.2
- dev-dependabot/npm_and_yarn/express-4.18.2
- dev-dependabot/npm_and_yarn/qs-and-express-6.11.0
- dev-dependabot/npm_and_yarn/decode-uri-component-0.2.2
- dev-dependabot/npm_and_yarn/loader-utils-and-webpack-cli-1.4.2
- dev-dependabot/npm_and_yarn/eventsource-1.1.1
- dev-dependabot/npm_and_yarn/url-parse-1.5.10
- dev-dependabot/npm_and_yarn/ajv-6.12.6
- dev-dependabot/npm_and_yarn/path-parse-1.0.7
- dev-dependabot/npm_and_yarn/ws-6.2.2
- dev-dependabot/npm_and_yarn/dns-packet-1.3.4
- dev-dependabot/npm_and_yarn/browserslist-4.16.6
- dev-dependabot/npm_and_yarn/lodash-4.17.21
- dev-dependabot/npm_and_yarn/ssri-6.0.2
- dev-dependabot/npm_and_yarn/y18n-4.0.1
- dev-dependabot/npm_and_yarn/elliptic-6.5.4
- dev-dependabot/npm_and_yarn/axios-0.21.1
- dev-dependabot/npm_and_yarn/ini-1.3.7
- dev-dependabot/npm_and_yarn/http-proxy-1.18.1
- dev-dependabot/npm_and_yarn/websocket-extensions-0.1.4
- dev-dependabot/npm_and_yarn/jquery-3.5.0
- dev-dependabot/npm_and_yarn/acorn-6.4.1
This package is auto-updated.
Last update: 2024-11-30 01:50:54 UTC
README
Laravel Multi Authentication
Installation video : click here or click below image
Note : Before Install and use this package run below command
Before Laravel version 6.0
php artisan make:auth
From Laravel Version 6.0
1. composer require laravel/ui
2. php artisan ui vue --auth
3. npm install
4. npm run dev
Install the Package
composer require codexshaper/laravel-permission
Publish Resource, Configs, Migration and Seeding Database in a single command
php artisan permission:install
Or Publish Resource, Configs, Migration and Seeding Database Manually
- Publish Configs
php artisan vendor:publish --tag=permission.config
- Publish Seeds
php artisan vendor:publish --tag=permission.seeds
- Migrate Database
php artisan migrate
- Run composer dump autoload
composer dump-autoload
- Seeding Database
php artisan db:seed --class=PermissionDatabaseSeeder
- Add Routes
Route::group(['prefix' => config('permission.prefix'),'middleware'=>['role:admin']], function () {
Permission::routes();
});
Import use CodexShaper\Permission\Traits\HasRoles
or simply use HasRoles
Trait into your App\User
Model
namespace App;
use CodexShaper\Permission\Traits\HasRoles;
class User extends Authenticatable
{
use HasRoles;
}
Check Permission go to /admin/laravel-permission
Install Demo
php artisan permission:install:demo
Demo url /admin/permissions
Publish Views
php artisan permission:publish:views
Publish Resources
php artisan permission:publish:resources
For Overriding Views and Resources, Change your config file /config/permission.php
'resources_path' => 'resources/views/vendor/permissions/assets',
'views' => 'resources/views/vendor/permissions/views',
Permission
use CodexShaper\Permission\Models\Permission;
$permission = Permission::create([
'name' => 'Browse',
'slug' => slug('browse'),
'created_at' => now(),
'updated_at' => now(),
]);
Give Permission to Roles
// Create Role before set permission
// $roles = [role_slug_or_id] ex: ['admin',1,2,'author']
$permission->givePermissionToRoles( $roles );
Update permission roles
$role_ids = [1,3,5]
$permission->syncPermissionToRoles( $role_ids );
Delete permission roles
// Delete specific Roles
$role_ids = [1,3,5];
$permission->revokePermissionsFromRoles( $role_ids );
// Delete all roles for current permission
$permission->revokePermissionsFromRoles();
Role
use CodexShaper\Permission\Models\Role;
$admin = Role::create([
'name' => 'Super Admin',
'slug' => 'admin',
'created_at' => now(),
'updated_at' => now(),
]);
Assign Permission
$admin->assignPermissions([
'browse',
'read',
'edit',
'add',
'delete'
]);
Update Permission
$permission_ids = [1,3,5]
$admin->syncPermissions( $permission_ids );
Delete permission
// Delete specific Permissions
$permission_ids = [1,3,5];
$admin->revokePermissions( $permission_ids );
// Delete all roles for current roles
$admin->revokePermissions();
Check Permission
$admin->hasPermission( $permission_slug );
User
use App\User;
$user = new User;
$user->name = 'John Doe';
$user->email = 'john@gmail.com';
$user->password = Hash::make('password');
$user->save();
$user->assignRoles('admin');
Assign Roles into existing user
$user = User::find(1);
$user->assignRoles('admin');
Assign Multiple roles
$user = User::find(1);
// Use pipe(|)
$user->assignRoles('admin|client|customer');
// Or use comma(,)
$user->assignRoles('admin,client,customer');
// Or use space
$user->assignRoles('admin client customer');
// Or Mixed
$user->assignRoles('admin client,customer|write');
// Pass custom separators
$separators = ',.| ';
$user->assignRoles('admin client,customer|write', $separators);
Update Roles
$role_ids = [1,2,3];
$user->syncRoles( $role_ids );
Delete Roles
// Delete specific Roles for current User
$role_ids = [1,3,5];
$user->revokeRoles( $role_ids );
// Delete all roles for current user
$user->revokeRoles();
Check Role
$user->hasRole( $role_slug );
Add Middleware on route
Route::group(['middleware'=>['role:admin']],function(){
// Routes
});
View Directories
@can('browse')
<p>You Can Browse</p>
@endcan
@role('admin')
<p>You are admin</p>
@endrole
@hasrole('admin')
<p>You have admin Permission</p>
@endhasrole
@haspermission('edit')
<p>You have admin Permission</p>
@endhaspermission
Authors
See also the list of contributors who participated in this project.
License
- MIT license
- Copyright 2019 © CodexShaper.