git add .
git commit "Implement admin roles and permissions system"
This commit is contained in:
@@ -6,7 +6,7 @@ use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\AdminUpdateRequest;
|
||||
use App\Http\Requests\AdminStoreRequest;
|
||||
use App\Models\Admin;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Role;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class AdminController extends Controller
|
||||
@@ -40,7 +40,9 @@ class AdminController extends Controller
|
||||
|
||||
public function edit(Admin $admin)
|
||||
{
|
||||
return view('admin.admins.edit',compact('admin'));
|
||||
$roles = Role::all();
|
||||
|
||||
return view('admin.admins.edit',compact('admin','roles'));
|
||||
}
|
||||
public function update( AdminUpdateRequest $request,Admin $admin)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class RoleController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$roles=Role::paginate(3);
|
||||
return view('admins.Roles.index',compact('roles'));
|
||||
}
|
||||
|
||||
public function permissions(Role $role)
|
||||
{
|
||||
$permissions=Permission::all();
|
||||
return view('admins.Roles.permissions',compact('role','permissions'));
|
||||
}
|
||||
public function updatePermissions(Request $request, Role $role)
|
||||
{
|
||||
$role->permissions()->sync($request->permissions ?? []);
|
||||
|
||||
return redirect()->back()->with('success','دسترسیها با موفقیت ذخیره شد');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -31,13 +31,18 @@ class AdminRole extends Model
|
||||
'role_id' => 'int'
|
||||
];
|
||||
|
||||
public function admin()
|
||||
{
|
||||
return $this->belongsTo(Admin::class);
|
||||
}
|
||||
public function roles()
|
||||
{
|
||||
return $this->belongsToMany(Role::class, 'admin_roles');
|
||||
}
|
||||
|
||||
public function role()
|
||||
{
|
||||
return $this->belongsTo(Role::class);
|
||||
}
|
||||
|
||||
public function hasPermission($permission)
|
||||
{
|
||||
return $this->roles()
|
||||
->whereHas('permissions', function ($query) use ($permission) {
|
||||
$query->where('slug', $permission);
|
||||
})
|
||||
->exists();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,37 @@
|
||||
<h3 class="mb-4">
|
||||
ویرایش مدیر
|
||||
</h3>
|
||||
<div class="mb-3">
|
||||
|
||||
<label class="form-label">
|
||||
نقشها
|
||||
</label>
|
||||
|
||||
|
||||
@foreach($roles as $role)
|
||||
|
||||
<div class="form-check">
|
||||
|
||||
<input
|
||||
class="form-check-input"
|
||||
type="checkbox"
|
||||
name="roles[]"
|
||||
value="{{ $role->id }}"
|
||||
|
||||
@checked(
|
||||
$admin->roles->contains($role->id)
|
||||
)
|
||||
>
|
||||
|
||||
<label class="form-check-label">
|
||||
{{ $role->name }}
|
||||
</label>
|
||||
|
||||
</div>
|
||||
|
||||
@endforeach
|
||||
|
||||
</div>
|
||||
|
||||
<form action="{{ route('admin.admins.update', $admin->id) }}" method="POST">
|
||||
|
||||
|
||||
@@ -31,6 +31,13 @@
|
||||
|
||||
</li>
|
||||
|
||||
<li class="nav-item mb-2">
|
||||
<a href="{{ route('admin.roles.index') }}"
|
||||
class="nav-link text-white"
|
||||
>
|
||||
مدیریت نقشها
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item mb-2">
|
||||
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
@extends('admin.layouts.app')
|
||||
|
||||
|
||||
@section('breadcrumb')
|
||||
<span>
|
||||
مدیریت نقشها
|
||||
</span>
|
||||
@endsection
|
||||
|
||||
|
||||
@section('content')
|
||||
|
||||
<div class="container mt-4">
|
||||
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
|
||||
<h5>
|
||||
لیست نقشها
|
||||
</h5>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="card shadow">
|
||||
|
||||
<div class="card-body">
|
||||
|
||||
|
||||
<div class="table-responsive">
|
||||
|
||||
<table class="table table-bordered text-center align-middle">
|
||||
|
||||
|
||||
<thead class="table-light">
|
||||
|
||||
<tr>
|
||||
|
||||
<th>
|
||||
شناسه
|
||||
</th>
|
||||
|
||||
<th>
|
||||
نام
|
||||
</th>
|
||||
|
||||
<th>
|
||||
نامک
|
||||
</th>
|
||||
|
||||
<th>
|
||||
توضیحات
|
||||
</th>
|
||||
|
||||
<th>
|
||||
عملیات
|
||||
</th>
|
||||
|
||||
</tr>
|
||||
|
||||
</thead>
|
||||
|
||||
|
||||
|
||||
<tbody>
|
||||
|
||||
|
||||
@forelse($roles as $role)
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<td>
|
||||
{{ $role->id }}
|
||||
</td>
|
||||
|
||||
|
||||
<td>
|
||||
{{ $role->name }}
|
||||
</td>
|
||||
|
||||
|
||||
<td>
|
||||
{{ $role->slug }}
|
||||
</td>
|
||||
|
||||
|
||||
<td>
|
||||
{{ $role->description }}
|
||||
</td>
|
||||
|
||||
|
||||
<td>
|
||||
|
||||
<a href="{{ route('admin.roles.permissions',$role) }}"
|
||||
class="btn btn-sm btn-primary">
|
||||
|
||||
مدیریت دسترسیها
|
||||
|
||||
</a>
|
||||
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
||||
@empty
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<td colspan="5">
|
||||
رکوردی وجود ندارد
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
||||
@endforelse
|
||||
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
|
||||
</div>
|
||||
{{ $roles->links() }}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
@@ -0,0 +1,75 @@
|
||||
@extends('admin.layouts.app')
|
||||
|
||||
|
||||
@section('content')
|
||||
|
||||
<div class="container mt-4">
|
||||
|
||||
|
||||
<div class="card">
|
||||
|
||||
<div class="card-header">
|
||||
دسترسیهای نقش:
|
||||
{{ $role->name }}
|
||||
</div>
|
||||
|
||||
|
||||
<div class="card-body">
|
||||
|
||||
|
||||
<form method="POST"
|
||||
action="{{ route('admin.roles.permissions.update',$role) }}">
|
||||
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
|
||||
@foreach($permissions as $permission)
|
||||
|
||||
<div class="form-check mb-2">
|
||||
|
||||
<input
|
||||
class="form-check-input"
|
||||
type="checkbox"
|
||||
name="permissions[]"
|
||||
value="{{ $permission->id }}"
|
||||
|
||||
@checked(
|
||||
$role->permissions->contains($permission->id)
|
||||
)
|
||||
>
|
||||
|
||||
|
||||
<label class="form-check-label">
|
||||
|
||||
{{ $permission->name }}
|
||||
|
||||
@if($permission->description)
|
||||
-
|
||||
{{ $permission->description }}
|
||||
@endif
|
||||
|
||||
</label>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@endforeach
|
||||
|
||||
|
||||
<button class="btn btn-primary mt-3">
|
||||
ذخیره
|
||||
</button>
|
||||
|
||||
|
||||
</form>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
@@ -6,6 +6,7 @@ use App\Http\Controllers\Admin\Auth\AuthController;
|
||||
use App\Http\Controllers\Admin\Auth\DashboardController;
|
||||
use App\Http\Controllers\Admin\UserController;
|
||||
use App\Http\Controllers\FlightController;
|
||||
use App\Http\Controllers\RoleController;
|
||||
use App\Http\Controllers\TourController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
@@ -88,7 +89,17 @@ Route::prefix('admin')->name('admin.')->group(function (){
|
||||
Route::delete('destroy','destroy')->name('destroy');
|
||||
});
|
||||
});
|
||||
Route::prefix('roles')->name('roles.')->controller(RoleController::class)->group(function () {
|
||||
|
||||
Route::get('/', 'index')->name('index');
|
||||
|
||||
Route::prefix('{role}')->group(function () {
|
||||
|
||||
Route::get('permissions', 'permissions')->name('permissions');
|
||||
|
||||
Route::put('permissions', 'updatePermissions')->name('permissions.update');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user