107 lines
2.8 KiB
PHP
107 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Repositories\RoleRepository;
|
|
use Illuminate\Http\Request;
|
|
use Spatie\Permission\Models\Permission;
|
|
use App\Repositories\PermissionRepository;
|
|
|
|
|
|
class PermissionsController extends Controller
|
|
{
|
|
private $permissionRepository;
|
|
private $role;
|
|
|
|
public function __construct(permissionRepository $permissionRepository,
|
|
RoleRepository $role)
|
|
{
|
|
$this->permissionRepository = $permissionRepository;
|
|
$this->role = $role;
|
|
}
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
$data['title'] = 'Permission Lists';
|
|
$data['permissionLists'] = $this->permissionRepository->getPermissionListsArrangedByPrefix();
|
|
$data['roles'] = $this->role->pluck();
|
|
$data['editable'] = false;
|
|
return view('crud.generated.permissions.index', $data);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
$data['editable'] = false;
|
|
$data['permissionLists'] = $this->permissionRepository->getPermissionListsArrangedByPrefix();
|
|
return view('user::role.create', $data);
|
|
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(string $id)
|
|
{
|
|
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(Permission $permission)
|
|
{
|
|
$data['title'] = "Edit Role";
|
|
$data['editable'] = true;
|
|
$data['role'] = $this->role->getRoleById($id);
|
|
$data['permissionIDsArray'] = $data['role']?->permissions?->pluck('id')->toArray();
|
|
$data['permissionLists'] = $this->permissionRepository->getPermissionListsArrangedByPrefix();
|
|
return view('user::role.edit', $data);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, Permission $permission)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
$permissionDelete = $this->permissionRepository->getPermissionById($id);
|
|
|
|
$permissionDelete->delete();
|
|
return response()->json(['status' => true, 'message' => 'Permission has been deleted'] );
|
|
}
|
|
|
|
public function generatePermissionFromRoutes()
|
|
{
|
|
try {
|
|
$this->permissionRepository->generatePermissionFromRoutes();
|
|
toastr()->success('Permission generated successfully!');
|
|
} catch (\Throwable $th) {
|
|
toastr()->error($th->getMessage());
|
|
|
|
}
|
|
return to_route('permissions.index');
|
|
|
|
}
|
|
}
|