Implémantation de la gestion des Services pouvant avoir des taches
This commit is contained in:
82
app/Http/Controllers/PermissionController.php
Normal file
82
app/Http/Controllers/PermissionController.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
|
||||
class PermissionController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if (!auth()->user()->hasRole('Admin')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
return Inertia::render('Permission/Index', [
|
||||
'permissions' => Permission::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
if (!auth()->user()->hasRole('Admin')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
return Inertia::render('Permission/Create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasRole('Admin')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|unique:permissions,name',
|
||||
]);
|
||||
|
||||
Permission::create(['name' => $validated['name']]);
|
||||
|
||||
return redirect()->route('permissions.index')->with('success', 'Permission créée avec succès.');
|
||||
}
|
||||
|
||||
public function edit(Permission $permission)
|
||||
{
|
||||
if (!auth()->user()->hasRole('Admin')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
return Inertia::render('Permission/Edit', [
|
||||
'permission' => $permission,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, Permission $permission)
|
||||
{
|
||||
if (!auth()->user()->hasRole('Admin')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|unique:permissions,name,' . $permission->id,
|
||||
]);
|
||||
|
||||
$permission->update(['name' => $validated['name']]);
|
||||
|
||||
return redirect()->route('permissions.index')->with('success', 'Permission mise à jour avec succès.');
|
||||
}
|
||||
|
||||
public function destroy(Permission $permission)
|
||||
{
|
||||
if (!auth()->user()->hasRole('Admin')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$permission->delete();
|
||||
|
||||
return redirect()->route('permissions.index')->with('success', 'Permission supprimée avec succès.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user