first commit
This commit is contained in:
0
Modules/User/app/Http/Controllers/.gitkeep
Normal file
0
Modules/User/app/Http/Controllers/.gitkeep
Normal file
92
Modules/User/app/Http/Controllers/PermissionController.php
Normal file
92
Modules/User/app/Http/Controllers/PermissionController.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\User\Repositories\PermissionInterface;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
|
||||
class PermissionController extends Controller
|
||||
{
|
||||
|
||||
private $permissionRepository;
|
||||
public function __construct(PermissionInterface $permissionRepository)
|
||||
{
|
||||
$this->permissionRepository = $permissionRepository;
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data['permissionLists'] = $this->permissionRepository->findAll();
|
||||
$data['title'] = 'Permission Lists';
|
||||
|
||||
return view('user::permissions.index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, Permission $permission)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(Permission $permission)
|
||||
{
|
||||
$permission->delete();
|
||||
toastr()->success('Permission has been deleted!');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function generatePermissionFromRoutes()
|
||||
{
|
||||
try {
|
||||
$this->permissionRepository->generatePermissionFromRoutes();
|
||||
toastr()->success('Permission generated successfully!');
|
||||
} catch (\Throwable $th) {
|
||||
toastr()->error($th->getMessage());
|
||||
|
||||
}
|
||||
|
||||
return to_route('permission.index');
|
||||
|
||||
}
|
||||
}
|
117
Modules/User/app/Http/Controllers/RoleController.php
Normal file
117
Modules/User/app/Http/Controllers/RoleController.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Modules\User\Repositories\PermissionInterface;
|
||||
use Modules\User\Repositories\RoleInterface;
|
||||
|
||||
class RoleController extends Controller
|
||||
{
|
||||
private $roleRepository;
|
||||
private $permissionRepository;
|
||||
public function __construct(RoleInterface $roleRepository, PermissionInterface $permissionRepository)
|
||||
{
|
||||
$this->roleRepository = $roleRepository;
|
||||
$this->permissionRepository = $permissionRepository;
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data['title'] = "Role Lists";
|
||||
$data['roles'] = $this->roleRepository->findAll();
|
||||
return view('user::role.index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$data['title'] = "Create Role";
|
||||
$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): RedirectResponse
|
||||
{
|
||||
try {
|
||||
|
||||
$validatedData = $request->validate([
|
||||
'name' => 'required',
|
||||
'guard_name' => 'string',
|
||||
]);
|
||||
|
||||
$role = $this->roleRepository->create($validatedData);
|
||||
|
||||
$role->permissions()->attach($request->permissions);
|
||||
|
||||
toastr()->success('New role has been created!');
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
toastr()->success($th->getMessage());
|
||||
}
|
||||
return redirect()->route('role.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$data['title'] = "Edit Role";
|
||||
$data['editable'] = true;
|
||||
$data['role'] = $this->roleRepository->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, $id): RedirectResponse
|
||||
{
|
||||
try {
|
||||
$validatedData = $request->validate([
|
||||
'name' => 'required',
|
||||
'guard_name' => 'string',
|
||||
]);
|
||||
|
||||
$role = $this->roleRepository->update($id, $validatedData);
|
||||
$role->permissions()->sync($request->permissions);
|
||||
|
||||
toastr()->success('Role has been updated!');
|
||||
} catch (\Throwable $th) {
|
||||
toastr()->error($th->getMessage());
|
||||
}
|
||||
return redirect()->route('role.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id): Response
|
||||
{
|
||||
$this->roleRepository->delete($id);
|
||||
toastr()->success('Role has been deleted!');
|
||||
return response()->json(['status' => true, 'message' => 'Role has been deleted!']);
|
||||
}
|
||||
}
|
142
Modules/User/app/Http/Controllers/UserController.php
Normal file
142
Modules/User/app/Http/Controllers/UserController.php
Normal file
@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Employee\Repositories\EmployeeInterface;
|
||||
use Modules\User\Repositories\RoleInterface;
|
||||
use Modules\User\Repositories\UserInterface;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
|
||||
protected $userRepository;
|
||||
protected $employeeRepository;
|
||||
protected $roleRepository;
|
||||
|
||||
public function __construct(UserInterface $userRepository, EmployeeInterface $employeeRepository, RoleInterface $roleRepository)
|
||||
{
|
||||
$this->userRepository = $userRepository;
|
||||
$this->employeeRepository = $employeeRepository;
|
||||
$this->roleRepository = $roleRepository;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data['editable'] = false;
|
||||
$data['users'] = $this->userRepository->findAll();
|
||||
$data['roleLists'] = $this->roleRepository->pluck();
|
||||
$data['employeeLists'] = $this->employeeRepository->pluck();
|
||||
return view('user::user.index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$data['title'] = "Create User";
|
||||
$data['roleLists'] = $this->roleRepository->pluck();
|
||||
$data['employeeLists'] = $this->employeeRepository->pluck();
|
||||
return view('user::user.create', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
try {
|
||||
|
||||
$validatedData = $request->validate([
|
||||
'name' => 'required|min:5',
|
||||
'email' => 'required',
|
||||
'password' => 'required',
|
||||
'employee_id' => 'required',
|
||||
]);
|
||||
|
||||
$user = $this->userRepository->create($validatedData, $request->role);
|
||||
|
||||
toastr()->success('User has been created!');
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
toastr()->error($th->getMessage());
|
||||
|
||||
}
|
||||
|
||||
return redirect()->route('user.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$data['user'] = $this->userRepository->getUserById($id);
|
||||
return view('user::user.show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$data['title'] = "Edit User";
|
||||
$data['roleLists'] = $this->roleRepository->pluck();
|
||||
$data['employeeLists'] = $this->employeeRepository->pluck();
|
||||
$data['user'] = $this->userRepository->getUserById($id);
|
||||
return view('user::user.edit', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id): RedirectResponse
|
||||
{
|
||||
try {
|
||||
|
||||
$validatedData = $request->validate([
|
||||
'name' => 'required|min:5',
|
||||
'email' => 'required',
|
||||
'password' => 'required',
|
||||
'employee_id' => 'required',
|
||||
]);
|
||||
|
||||
$user = $this->userRepository->update($id, $validatedData, $request->role);
|
||||
|
||||
toastr()->success('User has been updated!');
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
toastr()->error($th->getMessage());
|
||||
|
||||
}
|
||||
|
||||
return redirect()->route('user.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
|
||||
$this->userRepository->delete($id);
|
||||
|
||||
toastr()->success('User has been deleted!');
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
toastr()->error($th->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user