work on user role module

This commit is contained in:
Dharmaraj Shrestha 2024-04-09 18:00:26 +05:45
parent 4eace5b650
commit c019fcb02d
26 changed files with 419 additions and 82 deletions

View File

@ -8,7 +8,9 @@
<!-- end page title -->
{{ html()->form('POST')->route('employee.store')->class(['needs-validation'])->attributes(['novalidate', 'enctype' => 'multipart/form-data'])->open() }}
@include('employee::partials.action')
{{ html()->form()->close() }}
</div>

View File

@ -7,9 +7,10 @@
@include('layouts.partials.breadcrumb', ['title' => $title])
<!-- end page title -->
{{-- {{ html()->form('POST')->route('employee.store')->class(['needs-validation'])->attributes(['novalidate', 'enctype' => 'multipart/form-data'])->open() }} --}}
{{ html()->modelForm($employee, 'PUT')->route('employee.update', $employee->id)->class(['needs-validation'])->attributes(['novalidate', 'enctype' => 'multipart/form-data'])->open() }}
@include('employee::partials.action')
{{ html()->closeModelForm() }}
</div>

View File

@ -29,6 +29,7 @@ class LeaveController extends Controller
public function index()
{
$data['leaves'] = $this->leaveRepository->findAll();
return view('leave::index',$data);
}
@ -38,6 +39,7 @@ class LeaveController extends Controller
public function create()
{
$data['title'] = 'Create Leave';
return view('leave::create', $data);
}
@ -47,9 +49,13 @@ class LeaveController extends Controller
public function store(Request $request): RedirectResponse
{
$inputData = $request->all();
try {
$this->leaveRepository->create($inputData);
Toastr()->success('Leave Created Succesfully');
toastr()->success('Leave Created Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
@ -70,7 +76,9 @@ class LeaveController extends Controller
public function edit($id)
{
$data['title'] = 'Edit Leave';
$data['leave'] = $this->leaveRepository->getLeaveById($id);
return view('leave::edit',$data);
}
@ -81,8 +89,10 @@ class LeaveController extends Controller
{
$inputData = $request->all();
try {
$this->leaveRepository->update($id, $inputData);
toastr()->success('Leave Updated Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
@ -95,6 +105,7 @@ class LeaveController extends Controller
public function destroy($id)
{
$this->leaveRepository->delete($id);
toastr()->success('Leave Deleted Succesfully');
}
}

View File

@ -24,13 +24,13 @@
<div class="col-lg-8">
<div class="card">
<div class="card-body">
<form action="{{ route('leave.update', $leave->leave_id) }}" class="needs-validation" novalidate
method="post">
@csrf
@method('put')
<input type="hidden" name="leave_id" value="{{ $leave->leave_id }}">
{{ html()->modelForm($leave, 'PUT')->route('leave.update', $leave->id)->class(['needs-validation'])->attributes(['novalidate'])->open() }}
@include('leave::partials.action')
</form>
{{ html()->closeModelForm() }}
</div>
</div>
</div>

View File

@ -49,7 +49,7 @@
<div class="card-header align-items-center d-flex">
<h5 class="card-title flex-grow-1 mb-0">Leave Lists</h5>
<div class="flex-shrink-0">
<a href="{{ route('leave.create') }}" class="btn btn-success waves-effect waves-light btn-sm"><i
<a href="{{ route('leave.create') }}" class="btn btn-success waves-effect waves-light"><i
class="ri-add-fill me-1 align-bottom"></i> Add</a>
</div>
</div>

View File

@ -1,15 +1,9 @@
<div class="mb-3">
<label for="employee_id" class="form-label">Employee Name</label>
<input type="text" class="form-control" id="employee_id" placeholder="Enter employee name" name="employee_id"
value="{{ old('end_date', $leave->employee_id ?? '') }}" required>
<div class="invalid-feedback">
Please enter employee name.
</div>
</div>
{{-- <div class="mb-3">
<label for="employeeUrl" class="form-label">Employee Department URL</label>
<input type="url" class="form-control" id="employeeUrl" placeholder="Enter emploree url" name="employeeUrl">
</div> --}}
<div class="mb-3">
<label for="start_date" class="form-label">Start Leave Date</label>
@ -23,12 +17,6 @@
value="{{ old('end_date', $leave->end_date ?? '') }}">
</div>
{{--
<div class="mb-3">
<label for="VertimeassageInput" class="form-label">Message</label>
<textarea class="form-control" id="VertimeassageInput" rows="3" placeholder="Enter your message" name="remark"></textarea>
</div> --}}
<div class="text-end">
<button type="submit" class="btn btn-primary">{{ isset($leave) ? 'Update' : 'Add Leave' }}</button>
</div>

View File

@ -0,0 +1,93 @@
<?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\RoleRepository;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
class RoleController extends Controller
{
private $roleRepository;
public function __construct(RoleRepository $roleRepository){
$this->roleRepository = $roleRepository;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['roles'] = $this->roleRepository->findAll();
$data['editable'] = false;
return view('user::role.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['permissions'] = Permission::get();
$data['title'] = "Create Role";
return view('user::role.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$request->validate(['name' => 'required']);
$role = $this->roleRepository->create($request->all());
$role->syncPermissions($request->permissions);
toastr()->success('New role has been created!');
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(Role $role)
{
$data['permissions'] = Permission::get();
$data['role'] = $role;
$data['title'] = "Edit Role";
return view('user::role.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, Role $role)
{
$role->update(['name' => $request->name]);
$role->syncPermissions($request->permissions);
toastr()->success('Role has been updated!');
return redirect()->route('role.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Role $role)
{
$role->delete();
toastr()->success('Role has been deleted!');
}
}

View File

@ -22,9 +22,9 @@ class UserController extends Controller
public function index()
{
$data = User::latest()->get();
$editable = false;
return view('user::index', compact('data', 'editable'));
$data['editable'] = false;
$data['users'] = $this->userRepository->findAll();
return view('user::user.index', $data);
}
/**
@ -33,8 +33,7 @@ class UserController extends Controller
public function create()
{
$data['title'] = "Create User";
$data['users'] = User::latest()->get();
return view('user::create', $data);
return view('user::user.create', $data);
}
/**
@ -50,7 +49,7 @@ class UserController extends Controller
$user = $this->userRepository->create($validatedData, $request->role);
toastr()->success('User has been created!');
return redirect()->route('users.index');
return redirect()->route('user.index');
}
/**
@ -59,7 +58,8 @@ class UserController extends Controller
public function show($id)
{
return view('user::show');
$data['user'] = $this->userRepository->getUserById($id);
return view('user::user.show');
}
/**
@ -68,8 +68,8 @@ class UserController extends Controller
public function edit($id)
{
$data['title'] = "Edit User";
$data['user'] = User::findOrFail($id);
return view('user::edit', $data);
$data['user'] = $this->userRepository->getUserById($id);
return view('user::user.edit', $data);
}
/**

View File

@ -4,6 +4,10 @@ namespace Modules\User\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Modules\User\Repositories\RoleInterface;
use Modules\User\Repositories\RoleRepository;
use Modules\User\Repositories\UserInterface;
use Modules\User\Repositories\UserRepository;
class UserServiceProvider extends ServiceProvider
{
@ -29,6 +33,8 @@ class UserServiceProvider extends ServiceProvider
*/
public function register(): void
{
$this->app->bind(UserInterface::class, UserRepository::class);
$this->app->bind(RoleInterface::class, RoleRepository::class);
$this->app->register(RouteServiceProvider::class);
}

View File

@ -0,0 +1,12 @@
<?php
namespace Modules\User\Repositories;
interface RoleInterface
{
public function findAll();
public function getRoleById($roleId);
public function delete($roleId);
public function create(array $RoleDetails);
public function update($roleId, array $newDetails);
}

View File

@ -0,0 +1,34 @@
<?php
namespace Modules\User\Repositories;
use App\Models\Role;
class RoleRepository implements RoleInterface
{
public function findAll()
{
return Role::get();
}
public function getRoleById($roleId)
{
return Role::findOrFail($roleId);
}
public function delete($roleId)
{
Role::destroy($roleId);
}
public function create(array $roleDetails)
{
return Role::create($roleDetails);
}
public function update($roleId, array $newDetails)
{
return Role::whereId($roleId)->update($newDetails);
}
}

View File

@ -1,33 +0,0 @@
<div class="row gy-4">
<div class="col-md-4">
{{ html()->label('For Employee')->class('form-label') }}
{{ html()->select('employee_id', ['1', '2'])->class('form-select')->placeholder('Select Employee')->required() }}
</div>
<div class="col-md-4">
{{ html()->label('Role')->class('form-label') }}
{{ html()->select('role_id', ['1', '2'])->class('form-select')->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>

View File

@ -0,0 +1,12 @@
<div class="row gy-4">
<div class="col-md-4">
{{ html()->label('Name')->class('form-label') }}
{{ html()->text('name')->class('form-control')->placeholder('Enter Role Name')->required() }}
</div>
</div>
<div class="text-end">
<button type="submit" class="btn btn-primary">{{ $btnType }}</button>
</div>

View File

@ -8,7 +8,7 @@
<div class="modal-body">
<form action="{{ route('user.store') }}" class="needs-validation" novalidate method="post">
@csrf
@include('user::partials.action', ['btnType' => 'View'])
@include('user::partials.user.action', ['btnType' => 'View'])
</form>
</div>
</div>

View 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', ['1', '2'])->class('form-select')->placeholder('Select Employee')->required() }}
</div>
<div class="col-md-4">
{{ html()->label('Role')->class('form-label') }}
{{ html()->select('role_id', ['1', '2'])->class('form-select')->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>

View 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>

View File

@ -15,18 +15,17 @@
<li class="breadcrumb-item active">{{ $title }}</li>
</ol>
</div>
</div>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-lg-8">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<form action="{{ route('user.store') }}" class="needs-validation" novalidate method="post">
<form action="{{ route('role.store') }}" class="needs-validation" novalidate method="post">
@csrf
@include('user::partials.action', ['btnType' => 'Save'])
@include('user::partials.role.action', ['btnType' => 'Save'])
</form>
</div>
</div>

View 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

View File

@ -0,0 +1,62 @@
@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="">
<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>
@include('user::partials.user.view')
@endsection

View File

@ -25,7 +25,7 @@
<div class="card-body">
<form action="{{ route('user.store') }}" class="needs-validation" novalidate method="post">
@csrf
@include('user::partials.action', ['btnType' => 'Save'])
@include('user::partials.user.action', ['btnType' => 'Save'])
</form>
</div>
</div>

View 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

View File

@ -6,10 +6,15 @@
<div class="col-lg-12">
<div class="card">
<div class="card-header d-flex justify-content-between align-users-center">
<div class="card-header align-items-center d-flex">
<h5 class="card-title flex-grow-1 mb-0">User Lists</h5>
<a href="{{ route('user.create') }}" class="btn btn-info btn-sm"><span>Add New</span></a>
<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%">
@ -26,7 +31,7 @@
</tr>
</thead>
<tbody>
@foreach ($data as $index => $user)
@foreach ($users as $index => $user)
<tr data-id="{{ $user->id }}" data-display_order="{{ $user->display_order }}"
class="draggable-row">
<td class="tb-col">{{ $index + 1 }}</td>
@ -36,15 +41,15 @@
<td class="tb-col">{{ $user->roles->first()->id }}</td>
<td class="tb-col">
<div class="hstack flex-wrap gap-3">
<a href="javascript:void(0);" class="link-info fs-15 view-user-btn" data-bs-toggle="modal"
<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-user-btn"><i
<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-user-btn"><i
data-id="{{ $user->id }}" class="link-danger fs-15 remove-item-btn"><i
class="ri-delete-bin-line"></i></a>
</div>
</td>
@ -59,5 +64,5 @@
</div>
</div>
</div>
@include('user::partials.view')
@include('user::partials.user.view')
@endsection

View File

@ -1,6 +1,7 @@
<?php
use Illuminate\Support\Facades\Route;
use Modules\User\Http\Controllers\RoleController;
use Modules\User\Http\Controllers\UserController;
/*
@ -16,4 +17,5 @@ use Modules\User\Http\Controllers\UserController;
Route::group([], function () {
Route::resource('user', UserController::class)->names('user');
Route::resource('role', RoleController::class)->names('role');
});

View File

@ -68,9 +68,10 @@
class="nav-link @if (\Request::is('user/*')) active @endif">Users</a>
</li>
{{-- <li class="nav-item">
<a href="{{ route('role.index') }}" class="nav-link">Roles</a>
</li> --}}
<li class="nav-item">
<a href="{{ route('role.index') }}"
class="nav-link @if (\Request::is('role/*')) active @endif">Roles</a>
</li>
<li class="nav-item">
<a href="{{ route('countries.index') }}" class="nav-link">Countries</a>

View File

@ -32,12 +32,15 @@ Route::get('/initialize-db', function () {
});
// require __DIR__ . '/route.client.php';
Route::middleware('auth')->group(function () {
// require __DIR__ . '/CRUDgenerated/route.users.php';
// require __DIR__ . '/route.roles.php';
// require __DIR__ . '/route.rolepermissions.php';
// require __DIR__ . '/route.settings.php';
// require __DIR__ . '/route.form.php';
require __DIR__ . '/CRUDgenerated/route.countries.php';
require __DIR__ . '/CRUDgenerated/route.companytypes.php';