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());
|
||||
}
|
||||
}
|
||||
}
|
0
Modules/User/app/Http/Requests/.gitkeep
Normal file
0
Modules/User/app/Http/Requests/.gitkeep
Normal file
0
Modules/User/app/Models/.gitkeep
Normal file
0
Modules/User/app/Models/.gitkeep
Normal file
0
Modules/User/app/Providers/.gitkeep
Normal file
0
Modules/User/app/Providers/.gitkeep
Normal file
49
Modules/User/app/Providers/RouteServiceProvider.php
Normal file
49
Modules/User/app/Providers/RouteServiceProvider.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Called before routes are registered.
|
||||
*
|
||||
* Register any model bindings or pattern based filters.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the routes for the application.
|
||||
*/
|
||||
public function map(): void
|
||||
{
|
||||
$this->mapApiRoutes();
|
||||
|
||||
$this->mapWebRoutes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "web" routes for the application.
|
||||
*
|
||||
* These routes all receive session state, CSRF protection, etc.
|
||||
*/
|
||||
protected function mapWebRoutes(): void
|
||||
{
|
||||
Route::middleware('web')->group(module_path('User', '/routes/web.php'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "api" routes for the application.
|
||||
*
|
||||
* These routes are typically stateless.
|
||||
*/
|
||||
protected function mapApiRoutes(): void
|
||||
{
|
||||
Route::middleware('api')->prefix('api')->name('api.')->group(module_path('User', '/routes/api.php'));
|
||||
}
|
||||
}
|
123
Modules/User/app/Providers/UserServiceProvider.php
Normal file
123
Modules/User/app/Providers/UserServiceProvider.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Modules\User\Repositories\PermissionInterface;
|
||||
use Modules\User\Repositories\PermissionRepository;
|
||||
use Modules\User\Repositories\RoleInterface;
|
||||
use Modules\User\Repositories\RoleRepository;
|
||||
use Modules\User\Repositories\UserInterface;
|
||||
use Modules\User\Repositories\UserRepository;
|
||||
|
||||
class UserServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected string $moduleName = 'User';
|
||||
|
||||
protected string $moduleNameLower = 'user';
|
||||
|
||||
/**
|
||||
* Boot the application events.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
$this->registerCommands();
|
||||
$this->registerCommandSchedules();
|
||||
$this->registerTranslations();
|
||||
$this->registerConfig();
|
||||
$this->registerViews();
|
||||
$this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->bind(UserInterface::class, UserRepository::class);
|
||||
$this->app->bind(RoleInterface::class, RoleRepository::class);
|
||||
$this->app->bind(PermissionInterface::class, PermissionRepository::class);
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register commands in the format of Command::class
|
||||
*/
|
||||
protected function registerCommands(): void
|
||||
{
|
||||
// $this->commands([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register command Schedules.
|
||||
*/
|
||||
protected function registerCommandSchedules(): void
|
||||
{
|
||||
// $this->app->booted(function () {
|
||||
// $schedule = $this->app->make(Schedule::class);
|
||||
// $schedule->command('inspire')->hourly();
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
* Register translations.
|
||||
*/
|
||||
public function registerTranslations(): void
|
||||
{
|
||||
$langPath = resource_path('lang/modules/'.$this->moduleNameLower);
|
||||
|
||||
if (is_dir($langPath)) {
|
||||
$this->loadTranslationsFrom($langPath, $this->moduleNameLower);
|
||||
$this->loadJsonTranslationsFrom($langPath);
|
||||
} else {
|
||||
$this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower);
|
||||
$this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register config.
|
||||
*/
|
||||
protected function registerConfig(): void
|
||||
{
|
||||
$this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config');
|
||||
$this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register views.
|
||||
*/
|
||||
public function registerViews(): void
|
||||
{
|
||||
$viewPath = resource_path('views/modules/'.$this->moduleNameLower);
|
||||
$sourcePath = module_path($this->moduleName, 'resources/views');
|
||||
|
||||
$this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']);
|
||||
|
||||
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower);
|
||||
|
||||
$componentNamespace = str_replace('/', '\\', config('modules.namespace').'\\'.$this->moduleName.'\\'.ltrim(config('modules.paths.generator.component-class.path'), config('modules.paths.app_folder','')));
|
||||
Blade::componentNamespace($componentNamespace, $this->moduleNameLower);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*/
|
||||
public function provides(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
private function getPublishableViewPaths(): array
|
||||
{
|
||||
$paths = [];
|
||||
foreach (config('view.paths') as $path) {
|
||||
if (is_dir($path.'/modules/'.$this->moduleNameLower)) {
|
||||
$paths[] = $path.'/modules/'.$this->moduleNameLower;
|
||||
}
|
||||
}
|
||||
|
||||
return $paths;
|
||||
}
|
||||
}
|
0
Modules/User/app/Repositories/.gitkeep
Normal file
0
Modules/User/app/Repositories/.gitkeep
Normal file
16
Modules/User/app/Repositories/PermissionInterface.php
Normal file
16
Modules/User/app/Repositories/PermissionInterface.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Repositories;
|
||||
|
||||
interface PermissionInterface
|
||||
{
|
||||
public function findAll();
|
||||
public function getPermissionById($permissionId);
|
||||
public function delete($permissionId);
|
||||
public function create(array $permissionDetails);
|
||||
public function update($permissionId, array $newDetails);
|
||||
|
||||
public function getPermissionListsArrangedByPrefix();
|
||||
|
||||
public static function generatePermissionFromRoutes();
|
||||
}
|
91
Modules/User/app/Repositories/PermissionRepository.php
Normal file
91
Modules/User/app/Repositories/PermissionRepository.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
class PermissionRepository implements PermissionInterface
|
||||
{
|
||||
public function findAll()
|
||||
{
|
||||
return Permission::get();
|
||||
}
|
||||
|
||||
public function getPermissionById($permissionId)
|
||||
{
|
||||
return Permission::findOrFail($permissionId);
|
||||
}
|
||||
|
||||
public function delete($permissionId)
|
||||
{
|
||||
Permission::destroy($permissionId);
|
||||
}
|
||||
|
||||
public function create(array $permissionDetails)
|
||||
{
|
||||
return Permission::create($permissionDetails);
|
||||
}
|
||||
|
||||
public function update($permissionId, array $newDetails)
|
||||
{
|
||||
return Permission::where('id', $permissionId)->update($newDetails);
|
||||
}
|
||||
|
||||
public function getPermissionListsArrangedByPrefix()
|
||||
{
|
||||
$permissions = self::findAll();
|
||||
|
||||
$routeNameArr = [];
|
||||
foreach ($permissions as $permission) {
|
||||
if (!is_null($permission->name)) {
|
||||
$routeName = explode('.', $permission->name);
|
||||
if (is_array($routeName) && !empty($routeName[0])) {
|
||||
$routeNameArr[$routeName[0]][$permission->id] = array_key_exists(1, $routeName) ? $routeName[1] : $routeName[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $routeNameArr;
|
||||
}
|
||||
|
||||
public static function generatePermissionFromRoutes()
|
||||
{
|
||||
$routes = Route::getRoutes();
|
||||
|
||||
foreach ($routes as $route) {
|
||||
|
||||
$routeName = $route->getName();
|
||||
|
||||
$ignoreRoutes = [
|
||||
'debugbar',
|
||||
'login',
|
||||
'register',
|
||||
'logout',
|
||||
'post',
|
||||
'sanctum',
|
||||
'ignition',
|
||||
'welcome',
|
||||
'home',
|
||||
'api'
|
||||
];
|
||||
|
||||
$routePrefix = explode('.', $routeName);
|
||||
|
||||
if (is_array($routePrefix) && !empty($routePrefix[0])) {
|
||||
if (!in_array($routePrefix[0], $ignoreRoutes) && !Permission::where('name', $routeName)->exists()) {
|
||||
Permission::create(['name' => $routeName, 'guard_name' => 'web']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$roles = Role::all();
|
||||
foreach ($roles as $role) {
|
||||
|
||||
if ($role->name == 'admin' || $role->name == 'super-admin') {
|
||||
$role->givePermissionTo(Permission::all());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
13
Modules/User/app/Repositories/RoleInterface.php
Normal file
13
Modules/User/app/Repositories/RoleInterface.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Repositories;
|
||||
|
||||
interface RoleInterface
|
||||
{
|
||||
public function pluck();
|
||||
public function findAll();
|
||||
public function getRoleById($roleId);
|
||||
public function delete($roleId);
|
||||
public function create(array $RoleDetails);
|
||||
public function update($roleId, array $newDetails);
|
||||
}
|
43
Modules/User/app/Repositories/RoleRepository.php
Normal file
43
Modules/User/app/Repositories/RoleRepository.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Repositories;
|
||||
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
class RoleRepository implements RoleInterface
|
||||
{
|
||||
public function pluck()
|
||||
{
|
||||
return Role::pluck('name', 'id');
|
||||
}
|
||||
|
||||
public function findAll()
|
||||
{
|
||||
return Role::with('permissions')->get();
|
||||
}
|
||||
|
||||
public function getRoleById($roleId)
|
||||
{
|
||||
return Role::with('permissions')->findOrFail($roleId);
|
||||
}
|
||||
|
||||
public function delete($roleId)
|
||||
{
|
||||
$role = self::getRoleById($roleId);
|
||||
$role->permissions()->detach();
|
||||
return $role->delete();
|
||||
}
|
||||
|
||||
public function create(array $roleDetails)
|
||||
{
|
||||
return Role::create($roleDetails);
|
||||
}
|
||||
|
||||
public function update($roleId, array $newDetails)
|
||||
{
|
||||
$role = Role::find($roleId);
|
||||
$role->update($newDetails);
|
||||
return $role;
|
||||
}
|
||||
|
||||
}
|
12
Modules/User/app/Repositories/UserInterface.php
Normal file
12
Modules/User/app/Repositories/UserInterface.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Repositories;
|
||||
|
||||
interface UserInterface
|
||||
{
|
||||
public function findAll();
|
||||
public function getUserById($userId);
|
||||
public function delete($userId);
|
||||
public function create(array $UserDetails, array $role);
|
||||
public function update($userId, array $newDetails, array $role);
|
||||
}
|
40
Modules/User/app/Repositories/UserRepository.php
Normal file
40
Modules/User/app/Repositories/UserRepository.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Repositories;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
class UserRepository implements UserInterface
|
||||
{
|
||||
public function findAll()
|
||||
{
|
||||
return User::with(['employee.department'])->get();
|
||||
}
|
||||
|
||||
public function getUserById($userId)
|
||||
{
|
||||
return User::findOrFail($userId);
|
||||
}
|
||||
|
||||
public function create(array $userDetails, array $role)
|
||||
{
|
||||
$user = User::create($userDetails);
|
||||
$user->roles()->attach($role);
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function update($userId, array $newDetails, array $role)
|
||||
{
|
||||
$user = User::whereId($userId)->update($newDetails);
|
||||
$user->roles()->sync($role);
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function delete($userId)
|
||||
{
|
||||
$user = User::whereId($userId)->first();
|
||||
$user->roles()->detach();
|
||||
return $user->destroy();
|
||||
}
|
||||
|
||||
}
|
30
Modules/User/composer.json
Normal file
30
Modules/User/composer.json
Normal file
@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "nwidart/user",
|
||||
"description": "",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Widart",
|
||||
"email": "n.widart@gmail.com"
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [],
|
||||
"aliases": {
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Modules\\User\\": "app/",
|
||||
"Modules\\User\\Database\\Factories\\": "database/factories/",
|
||||
"Modules\\User\\Database\\Seeders\\": "database/seeders/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Modules\\User\\Tests\\": "tests/"
|
||||
}
|
||||
}
|
||||
}
|
0
Modules/User/config/.gitkeep
Normal file
0
Modules/User/config/.gitkeep
Normal file
5
Modules/User/config/config.php
Normal file
5
Modules/User/config/config.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'name' => 'User',
|
||||
];
|
0
Modules/User/database/factories/.gitkeep
Normal file
0
Modules/User/database/factories/.gitkeep
Normal file
0
Modules/User/database/migrations/.gitkeep
Normal file
0
Modules/User/database/migrations/.gitkeep
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->unsignedInteger('employee_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
|
||||
});
|
||||
}
|
||||
};
|
0
Modules/User/database/seeders/.gitkeep
Normal file
0
Modules/User/database/seeders/.gitkeep
Normal file
16
Modules/User/database/seeders/UserDatabaseSeeder.php
Normal file
16
Modules/User/database/seeders/UserDatabaseSeeder.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\database\seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class UserDatabaseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
}
|
||||
}
|
11
Modules/User/module.json
Normal file
11
Modules/User/module.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "User",
|
||||
"alias": "user",
|
||||
"description": "",
|
||||
"keywords": [],
|
||||
"priority": 0,
|
||||
"providers": [
|
||||
"Modules\\User\\Providers\\UserServiceProvider"
|
||||
],
|
||||
"files": []
|
||||
}
|
15
Modules/User/package.json
Normal file
15
Modules/User/package.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"axios": "^1.1.2",
|
||||
"laravel-vite-plugin": "^0.7.5",
|
||||
"sass": "^1.69.5",
|
||||
"postcss": "^8.3.7",
|
||||
"vite": "^4.0.0"
|
||||
}
|
||||
}
|
0
Modules/User/resources/assets/.gitkeep
Normal file
0
Modules/User/resources/assets/.gitkeep
Normal file
0
Modules/User/resources/assets/js/app.js
Normal file
0
Modules/User/resources/assets/js/app.js
Normal file
0
Modules/User/resources/assets/sass/app.scss
Normal file
0
Modules/User/resources/assets/sass/app.scss
Normal file
0
Modules/User/resources/views/.gitkeep
Normal file
0
Modules/User/resources/views/.gitkeep
Normal file
29
Modules/User/resources/views/layouts/master.blade.php
Normal file
29
Modules/User/resources/views/layouts/master.blade.php
Normal file
@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
|
||||
<title>User Module - {{ config('app.name', 'Laravel') }}</title>
|
||||
|
||||
<meta name="description" content="{{ $description ?? '' }}">
|
||||
<meta name="keywords" content="{{ $keywords ?? '' }}">
|
||||
<meta name="author" content="{{ $author ?? '' }}">
|
||||
|
||||
<!-- Fonts -->
|
||||
<link rel="preconnect" href="https://fonts.bunny.net">
|
||||
<link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />
|
||||
|
||||
{{-- Vite CSS --}}
|
||||
{{-- {{ module_vite('build-user', 'resources/assets/sass/app.scss') }} --}}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@yield('content')
|
||||
|
||||
{{-- Vite JS --}}
|
||||
{{-- {{ module_vite('build-user', 'resources/assets/js/app.js') }} --}}
|
||||
</body>
|
138
Modules/User/resources/views/partials/role/action.blade.php
Normal file
138
Modules/User/resources/views/partials/role/action.blade.php
Normal file
@ -0,0 +1,138 @@
|
||||
<div class="row gy-4">
|
||||
|
||||
<div class="col-lg-4">
|
||||
{{ html()->label('Name')->class('form-label') }}
|
||||
{{ html()->text('name')->class('form-control')->placeholder('Enter Role Name')->required() }}
|
||||
</div>
|
||||
|
||||
<div class="col-lg-4">
|
||||
{{ html()->label('Guard Name')->class('form-label') }}
|
||||
{{ html()->text('guard_name', 'web')->class('form-control')->isReadonly($readonly = true) }}
|
||||
</div>
|
||||
|
||||
<div class="col-lg-2">
|
||||
<div class="form-check form-switch form-switch-lg mt-3">
|
||||
{{ html()->checkbox('all_permissions_check')->class('form-check-input')->id('all-check') }}
|
||||
{{ html()->label('Select All')->class('form-check-label')->for('all-check') }}
|
||||
</div>
|
||||
{{ html()->p()->text('Enable all Permissions for this role')->class('fs-6 text-muted mt-1') }}
|
||||
</div>
|
||||
|
||||
<div class="col-lg-2">
|
||||
<x-form-buttons :editable=$editable label='Assign' />
|
||||
</div>
|
||||
|
||||
@foreach ($permissionLists as $key => $permission)
|
||||
<div class="col-lg-4">
|
||||
{{-- <p class="justify-center text-soft-success"> --}}
|
||||
<div class="form-check form-switch form-switch-custom form-switch-success mb-3">
|
||||
<input class="form-check-input parent-switch" type="checkbox" role="switch" id="check_{{ $key }}">
|
||||
<label class="form-check-label ms-2" for="{check_{$key}}">{{ Str::ucfirst($key) }}</label>
|
||||
</div>
|
||||
{{-- {{ Str::ucfirst($key) }}
|
||||
</p> --}}
|
||||
<fieldset class="rounded-2 p-3">
|
||||
<legend class="fs-5">Permissions</legend>
|
||||
<div class="row">
|
||||
|
||||
@foreach ($permission as $index => $item)
|
||||
<div class="col-lg-12">
|
||||
<div class="form-check form-check-success">
|
||||
{{ html()->checkbox('permissions[]')->id('permission_' . $index)->value($index)->class('form-check-input child-checkbox')->checked($editable && in_array($index, $permissionIDsArray)) }}
|
||||
{{ html()->label(Str::ucfirst($item))->for('permission_' . $index)->class('form-check-label ms-2') }}
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
|
||||
|
||||
@push('js')
|
||||
<script type="text/javascript">
|
||||
// $(document).ready(function() {
|
||||
|
||||
// // Cache selectors
|
||||
// const childCheckboxes = $('.child-checkbox');
|
||||
// const parentSwitches = $('.parent-switch');
|
||||
// const allCheck = $('#all-check');
|
||||
|
||||
// // Initial selection (optional, can be removed if not needed)
|
||||
// childCheckboxes.trigger('change');
|
||||
|
||||
// // Parent switch and child checkbox change handler (combined)
|
||||
// $('.child-checkbox, .parent-switch').change(function() {
|
||||
// const currentCol = $(this).closest('.col-lg-4');
|
||||
// const currentSwitch = currentCol.find('.parent-switch');
|
||||
// const currentChildren = currentCol.find(childCheckboxes);
|
||||
|
||||
// let allChecked = true;
|
||||
// currentChildren.each(function() {
|
||||
// if (!$(this).prop('checked')) {
|
||||
// allChecked = false;
|
||||
// return false;
|
||||
// }
|
||||
// });
|
||||
|
||||
// currentSwitch.prop('checked', allChecked);
|
||||
// allCheck.prop('checked', childCheckboxes.prop(
|
||||
// 'checked')); // Check all checkbox state
|
||||
// });
|
||||
|
||||
// // "all-check" change handler
|
||||
// allCheck.change(function() {
|
||||
// childCheckboxes.prop('checked', this.checked).trigger('change');
|
||||
// });
|
||||
|
||||
// });
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
$('.child-checkbox').trigger('change');
|
||||
|
||||
$('.parent-switch').change(function() {
|
||||
let childCheckboxes = $(this).closest('.col-lg-4').find('.child-checkbox');
|
||||
childCheckboxes.prop('checked', this.checked);
|
||||
});
|
||||
|
||||
$('.child-checkbox').change(function() {
|
||||
let parentSwitch = $(this).closest('.col-lg-4').find('.parent-switch');
|
||||
let childCheckboxes = $(this).closest('.col-lg-4').find('.child-checkbox');
|
||||
let allChecked = true;
|
||||
childCheckboxes.each(function() {
|
||||
if (!$(this).prop('checked')) {
|
||||
allChecked = false;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
parentSwitch.prop('checked', allChecked);
|
||||
});
|
||||
|
||||
$('#all-check').change(function() {
|
||||
let childCheckboxes = $('.child-checkbox');
|
||||
childCheckboxes.prop('checked', this.checked);
|
||||
|
||||
childCheckboxes.prop('checked', this.checked).trigger('change');
|
||||
});
|
||||
|
||||
$('.child-checkbox, .parent-switch').change(function() {
|
||||
let allCheck = $('#all-check');
|
||||
let childCheckboxes = $('.child-checkbox');
|
||||
let allChecked = true;
|
||||
|
||||
childCheckboxes.each((index, checkBox) => {
|
||||
if (!$(checkBox).prop('checked')) {
|
||||
allChecked = false;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
allCheck.prop('checked', allChecked);
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
@endpush
|
16
Modules/User/resources/views/partials/role/view.blade.php
Normal file
16
Modules/User/resources/views/partials/role/view.blade.php
Normal file
@ -0,0 +1,16 @@
|
||||
<div class="modal fade" id="viewModal" tabindex="-1" aria-labelledby="viewModalLabel" aria-modal="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalgridLabel">View User</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form action="{{ route('user.store') }}" class="needs-validation" novalidate method="post">
|
||||
@csrf
|
||||
@include('user::partials.user.action', ['btnType' => 'View'])
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
33
Modules/User/resources/views/partials/user/action.blade.php
Normal file
33
Modules/User/resources/views/partials/user/action.blade.php
Normal file
@ -0,0 +1,33 @@
|
||||
<div class="row gy-4">
|
||||
|
||||
<div class="col-md-4">
|
||||
{{ html()->label('For Employee')->class('form-label') }}
|
||||
{{ html()->select('employee_id', $employeeLists)->class('form-select select2')->placeholder('Select Employee')->required() }}
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
{{ html()->label('Role')->class('form-label') }}
|
||||
{{ html()->select('role_id',$roleLists)->class('form-select select2')->placeholder('Select Role')->required() }}
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
{{ html()->label('Username')->class('form-label') }}
|
||||
{{ html()->text('name')->class('form-control')->placeholder('Enter Username')->required() }}
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
{{ html()->label('Email')->class('form-label') }}
|
||||
{{ html()->email('email')->class('form-control')->placeholder('Enter Email')->required() }}
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-md-4">
|
||||
{{ html()->label('Password')->class('form-label') }}
|
||||
{{ html()->password('password')->class('form-control')->placeholder('Enter Password')->required() }}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="text-end">
|
||||
<button type="submit" class="btn btn-primary">{{ $btnType }}</button>
|
||||
</div>
|
16
Modules/User/resources/views/partials/user/view.blade.php
Normal file
16
Modules/User/resources/views/partials/user/view.blade.php
Normal file
@ -0,0 +1,16 @@
|
||||
<div class="modal fade" id="viewModal" tabindex="-1" aria-labelledby="viewModalLabel" aria-modal="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalgridLabel">View User</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form action="{{ route('user.store') }}" class="needs-validation" novalidate method="post">
|
||||
@csrf
|
||||
@include('user::partials.user.action', ['btnType' => 'View'])
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
51
Modules/User/resources/views/permissions/index.blade.php
Normal file
51
Modules/User/resources/views/permissions/index.blade.php
Normal file
@ -0,0 +1,51 @@
|
||||
@extends('layouts.app')
|
||||
@section('content')
|
||||
<div class="page-content">
|
||||
<div class="container-fluid">
|
||||
|
||||
<!-- start page title -->
|
||||
@include('layouts.partials.breadcrumb', ['title' => $title])
|
||||
|
||||
<!-- end page title -->
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header align-items-center d-flex">
|
||||
<h5 class="card-title flex-grow-1 mb-0">{{ $title }}</h5>
|
||||
<div class="flex-shrink-0">
|
||||
<a href="{{ route('permission.generatePermissionFromRoutes') }}"
|
||||
class="btn btn-success waves-effect waves-light"><i
|
||||
class="ri-add-fill me-1 align-bottom"></i>Generate Permissions</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<table id="model-datatables" class="display table table-bordered dt-responsive" style="width:100%">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>S.N</th>
|
||||
<th>Name</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($permissionLists as $index => $item)
|
||||
<tr>
|
||||
<td class="tb-col">{{ $index + 1 }}</td>
|
||||
<td class="tb-col">{{ $item->name }}</td>
|
||||
<td class="tb-col">
|
||||
<a href="javascript:void(0);"
|
||||
data-link="{{ route('permission.destroy', $item->id) }}"
|
||||
data-id="{{ $item->id }}" class="link-danger fs-15 remove-item-btn"><i
|
||||
class="ri-delete-bin-line"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<x-data-table-script />
|
||||
@endsection
|
43
Modules/User/resources/views/role/create.blade.php
Normal file
43
Modules/User/resources/views/role/create.blade.php
Normal file
@ -0,0 +1,43 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<div class="page-content">
|
||||
<div class="container-fluid">
|
||||
<!-- start page title -->
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="page-title-box d-sm-flex align-items-center justify-content-between">
|
||||
<h4 class="mb-sm-0">{{ $title }}</h4>
|
||||
|
||||
<div class="page-title-right">
|
||||
<ol class="breadcrumb m-0">
|
||||
<li class="breadcrumb-item"><a href="javascript: void(0);">Dashboards</a></li>
|
||||
<li class="breadcrumb-item active">{{ $title }}</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end page title -->
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<form action="{{ route('role.store') }}" class="needs-validation" novalidate method="post">
|
||||
@csrf
|
||||
@include('user::partials.role.action', ['btnType' => 'Save'])
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--end row-->
|
||||
|
||||
</div>
|
||||
<!-- container-fluid -->
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('js')
|
||||
<script src="{{ asset('assets/js/pages/form-validation.init.js') }}"></script>
|
||||
@endpush
|
45
Modules/User/resources/views/role/edit.blade.php
Normal file
45
Modules/User/resources/views/role/edit.blade.php
Normal file
@ -0,0 +1,45 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<div class="page-content">
|
||||
<div class="container-fluid">
|
||||
<!-- start page title -->
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="page-title-box d-sm-flex align-items-center justify-content-between">
|
||||
<h4 class="mb-sm-0">{{ $title }}</h4>
|
||||
|
||||
<div class="page-title-right">
|
||||
<ol class="breadcrumb m-0">
|
||||
<li class="breadcrumb-item"><a href="javascript: void(0);">Dashboards</a></li>
|
||||
<li class="breadcrumb-item active">{{ $title }}</li>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end page title -->
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
{{ html()->modelForm($role, 'PUT')->route('role.update', $role->id)->class(['needs-validation'])->attributes(['novalidate'])->open() }}
|
||||
|
||||
@include('user::partials.role.action', ['btnType' => 'Save'])
|
||||
|
||||
{{ html()->closeModelForm() }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--end row-->
|
||||
|
||||
</div>
|
||||
<!-- container-fluid -->
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('js')
|
||||
<script src="{{ asset('assets/js/pages/form-validation.init.js') }}"></script>
|
||||
@endpush
|
61
Modules/User/resources/views/role/index.blade.php
Normal file
61
Modules/User/resources/views/role/index.blade.php
Normal file
@ -0,0 +1,61 @@
|
||||
@extends('layouts.app')
|
||||
@section('content')
|
||||
<div class="page-content">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
|
||||
<div class="col-lg-12">
|
||||
<div class="card">
|
||||
|
||||
<div class="card-header align-items-center d-flex">
|
||||
<h5 class="card-title flex-grow-1 mb-0">Role Lists</h5>
|
||||
<div class="flex-shrink-0">
|
||||
<a href="{{ route('role.create') }}" class="btn btn-success waves-effect waves-light"><i
|
||||
class="ri-add-fill me-1 align-bottom"></i> Create Role</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table id="buttons-datatables" class="display table-sm table-bordered table" style="width:100%">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th class="tb-col"><span class="overline-title">S.N</span></th>
|
||||
<th class="tb-col"><span class="overline-title">Name</span></th>
|
||||
<th class="tb-col"><span class="overline-title">Guard</span></th>
|
||||
<th class="tb-col" data-sortable="false"><span class="overline-title">Action</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($roles as $index => $role)
|
||||
<tr>
|
||||
<td class="tb-col">{{ $index + 1 }}</td>
|
||||
<td class="tb-col">{{ $role->name }}</td>
|
||||
<td class="tb-col">{{ $role->guard_name }}</td>
|
||||
<td class="tb-col">
|
||||
<div class="hstack flex-wrap gap-3">
|
||||
<a href="javascript:void(0);" class="link-info fs-15 view-item-btn" data-bs-toggle="modal"
|
||||
data-bs-target="#viewModal">
|
||||
<i class="ri-eye-line"></i>
|
||||
</a>
|
||||
<a href="{{ route('role.edit', $role->id) }}" class="link-success fs-15 edit-item-btn"><i
|
||||
class="ri-edit-2-line"></i></a>
|
||||
|
||||
<a href="javascript:void(0);" data-link="{{ route('role.destroy', $role->id) }}"
|
||||
data-id="{{ $role->id }}" class="link-danger fs-15 remove-item-btn"><i
|
||||
class="ri-delete-bin-line"></i></a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
43
Modules/User/resources/views/user/create.blade.php
Normal file
43
Modules/User/resources/views/user/create.blade.php
Normal file
@ -0,0 +1,43 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<div class="page-content">
|
||||
<div class="container-fluid">
|
||||
<!-- start page title -->
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="page-title-box d-sm-flex align-items-center justify-content-between">
|
||||
<h4 class="mb-sm-0">{{ $title }}</h4>
|
||||
|
||||
<div class="page-title-right">
|
||||
<ol class="breadcrumb m-0">
|
||||
<li class="breadcrumb-item"><a href="javascript: void(0);">Dashboards</a></li>
|
||||
<li class="breadcrumb-item active">{{ $title }}</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end page title -->
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<form action="{{ route('user.store') }}" class="needs-validation" novalidate method="post">
|
||||
@csrf
|
||||
@include('user::partials.user.action', ['btnType' => 'Save'])
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--end row-->
|
||||
|
||||
</div>
|
||||
<!-- container-fluid -->
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('js')
|
||||
<script src="{{ asset('assets/js/pages/form-validation.init.js') }}"></script>
|
||||
@endpush
|
45
Modules/User/resources/views/user/edit.blade.php
Normal file
45
Modules/User/resources/views/user/edit.blade.php
Normal file
@ -0,0 +1,45 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<div class="page-content">
|
||||
<div class="container-fluid">
|
||||
<!-- start page title -->
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="page-title-box d-sm-flex align-items-center justify-content-between">
|
||||
<h4 class="mb-sm-0">{{ $title }}</h4>
|
||||
|
||||
<div class="page-title-right">
|
||||
<ol class="breadcrumb m-0">
|
||||
<li class="breadcrumb-item"><a href="javascript: void(0);">Dashboards</a></li>
|
||||
<li class="breadcrumb-item active">{{ $title }}</li>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end page title -->
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
{{ html()->modelForm($user, 'PUT')->route('user.update', $user->id)->class(['needs-validation'])->attributes(['novalidate'])->open() }}
|
||||
|
||||
@include('user::partials.user.action', ['btnType' => 'Save'])
|
||||
|
||||
{{ html()->closeModelForm() }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--end row-->
|
||||
|
||||
</div>
|
||||
<!-- container-fluid -->
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('js')
|
||||
<script src="{{ asset('assets/js/pages/form-validation.init.js') }}"></script>
|
||||
@endpush
|
75
Modules/User/resources/views/user/index.blade.php
Normal file
75
Modules/User/resources/views/user/index.blade.php
Normal file
@ -0,0 +1,75 @@
|
||||
@extends('layouts.app')
|
||||
@section('content')
|
||||
<div class="page-content">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
|
||||
<div class="col-lg-12">
|
||||
<div class="card">
|
||||
|
||||
<div class="card-header align-items-center d-flex">
|
||||
<h5 class="card-title flex-grow-1 mb-0">User Lists</h5>
|
||||
<div class="flex-shrink-0">
|
||||
<a href="{{ route('user.create') }}" class="btn btn-success waves-effect waves-light"><i
|
||||
class="ri-add-fill me-1 align-bottom"></i> Create User</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table id="buttons-datatables" class="display table-sm table-bordered table"
|
||||
style="width:100%">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th class="tb-col"><span class="overline-title">S.N</span></th>
|
||||
<th class="tb-col"><span class="overline-title">Username</span></th>
|
||||
<th class="tb-col"><span class="overline-title">Email</span></th>
|
||||
<th class="tb-col"><span class="overline-title">Employee</span></th>
|
||||
<th class="tb-col"><span class="overline-title">Role</span></th>
|
||||
<th class="tb-col" data-sortable="false"><span
|
||||
class="overline-title">Action</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($users as $index => $user)
|
||||
<tr>
|
||||
<td class="tb-col">{{ $index + 1 }}</td>
|
||||
<td class="tb-col">{{ $user->name }}</td>
|
||||
<td class="tb-col">{{ $user->email }}</td>
|
||||
<td class="tb-col">
|
||||
{{ $user->employee?->full_name }}
|
||||
<p class="small text-muted">{{ $user->employee?->department?->name }}
|
||||
</p>
|
||||
</td>
|
||||
<td class="tb-col">{{ $user->roles?->first()?->name }}</td>
|
||||
<td class="tb-col">
|
||||
<div class="hstack flex-wrap gap-3">
|
||||
<a href="javascript:void(0);" class="link-info fs-15 view-item-btn"
|
||||
data-bs-toggle="modal" data-bs-target="#viewModal">
|
||||
<i class="ri-eye-line"></i>
|
||||
</a>
|
||||
<a href="{{ route('user.edit', $user->id) }}"
|
||||
class="link-success fs-15 edit-item-btn"><i
|
||||
class="ri-edit-2-line"></i></a>
|
||||
|
||||
<a href="javascript:void(0);"
|
||||
data-link="{{ route('user.destroy', $user->id) }}"
|
||||
data-id="{{ $user->id }}"
|
||||
class="link-danger fs-15 remove-item-btn"><i
|
||||
class="ri-delete-bin-line"></i></a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@include('user::partials.user.view')
|
||||
@endsection
|
0
Modules/User/routes/.gitkeep
Normal file
0
Modules/User/routes/.gitkeep
Normal file
19
Modules/User/routes/api.php
Normal file
19
Modules/User/routes/api.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\User\Http\Controllers\UserController;
|
||||
|
||||
/*
|
||||
*--------------------------------------------------------------------------
|
||||
* API Routes
|
||||
*--------------------------------------------------------------------------
|
||||
*
|
||||
* Here is where you can register API routes for your application. These
|
||||
* routes are loaded by the RouteServiceProvider within a group which
|
||||
* is assigned the "api" middleware group. Enjoy building your API!
|
||||
*
|
||||
*/
|
||||
|
||||
Route::middleware(['auth:sanctum'])->prefix('v1')->group(function () {
|
||||
Route::apiResource('user', UserController::class)->names('user');
|
||||
});
|
23
Modules/User/routes/web.php
Normal file
23
Modules/User/routes/web.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\User\Http\Controllers\PermissionController;
|
||||
use Modules\User\Http\Controllers\RoleController;
|
||||
use Modules\User\Http\Controllers\UserController;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Web Routes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here is where you can register web routes for your application. These
|
||||
| routes are loaded by the RouteServiceProvider within a group which
|
||||
| contains the "web" middleware group. Now create something great!
|
||||
|
|
||||
*/
|
||||
|
||||
Route::group([], function () {
|
||||
Route::resource('user', UserController::class)->names('user');
|
||||
Route::resource('role', RoleController::class)->names('role');
|
||||
Route::resource('permission', PermissionController::class)->names('permission')->only(['index','destroy']);
|
||||
});
|
26
Modules/User/vite.config.js
Normal file
26
Modules/User/vite.config.js
Normal file
@ -0,0 +1,26 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import laravel from 'laravel-vite-plugin';
|
||||
|
||||
export default defineConfig({
|
||||
build: {
|
||||
outDir: '../../public/build-user',
|
||||
emptyOutDir: true,
|
||||
manifest: true,
|
||||
},
|
||||
plugins: [
|
||||
laravel({
|
||||
publicDirectory: '../../public',
|
||||
buildDirectory: 'build-user',
|
||||
input: [
|
||||
__dirname + '/resources/assets/sass/app.scss',
|
||||
__dirname + '/resources/assets/js/app.js'
|
||||
],
|
||||
refresh: true,
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
//export const paths = [
|
||||
// 'Modules/User/resources/assets/sass/app.scss',
|
||||
// 'Modules/User/resources/assets/js/app.js',
|
||||
//];
|
Reference in New Issue
Block a user