alikazemayni / easy_permission
This package is for creating a simple authentication system
Installs: 19
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/alikazemayni/easy_permission
Requires
- php: 8.1
- miladshm/controller-helpers: 0.8.6
README
description : This package is for creating a simple authentication system in laravel
Install package :
composer require alikazemayni/easy_permission
Publish files :
php artisan vendor:publish --tag publish-permissions-file
Migrate :
php artisan migrate
User relation :
public function permissions(): BelongsToMany { $this->belongsToMany(Permission::class, 'user_permission', 'user_id', 'permissions_id')->withTimestamps(); }
Get all permission and user permission :
ResponderFacade::setData( Permissions::with( ['users' => fn($q) => $q->where('user_id' , $request->user_id),'section'] ) ->get() )->respond();
Sync user permission :
public function user(Request $request): JsonResponse{ $permissions = User::findOrFail($request->user_id)->permissions(); $permissions->sync($request->permissions); }
Add user from role :
$role_permission = Role::findOrFail($request->role_id)->permissions->pluck('id'); if ($request->force) User::findOrFail($request->user_id)->permissions() ->wherePivot('type', 'role')->delete(); User::findOrFail($request->user_id)->permissions() ->syncWithPivotValues($role_permission, ['type' => 'role']); Role::findOrFail($request->role_id)->users()->attach($request->user_id);
Remove user from role
User::findOrFail($request->user_id)->permissions()->wherePivot('type', 'role')->detach(); Role::findOrFail($request->role_id)->users() ->wherePivot('user_id', $request->user_id)->detach();