setup module

This commit is contained in:
Dharmaraj Shrestha 2024-04-10 18:06:18 +05:45
parent e0fe321cb7
commit 1dbc6cabf8
11 changed files with 215 additions and 158 deletions

View File

@ -3,13 +3,13 @@
namespace Modules\Employee\Http\Controllers; namespace Modules\Employee\Http\Controllers;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Role;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Modules\Employee\Repositories\EmployeeInterface; use Modules\Employee\Repositories\EmployeeInterface;
use Modules\User\Repositories\UserInterface; use Modules\User\Repositories\UserInterface;
use Spatie\Permission\Models\Role;
class EmployeeController extends Controller class EmployeeController extends Controller
{ {
@ -53,6 +53,7 @@ class EmployeeController extends Controller
*/ */
public function store(Request $request) public function store(Request $request)
{ {
dd($request->all());
$inputData = $request->all(); $inputData = $request->all();
try { try {
@ -63,8 +64,11 @@ class EmployeeController extends Controller
} }
$this->employeeRepository->create($inputData); $this->employeeRepository->create($inputData);
toastr()->success('Employee Created Succesfully'); toastr()->success('Employee Created Succesfully');
} catch (\Throwable $th) { } catch (\Throwable $th) {
echo $th->getMessage();
toastr()->error($th->getMessage()); toastr()->error($th->getMessage());
} }
return redirect()->route('employee.index'); return redirect()->route('employee.index');
@ -114,19 +118,25 @@ class EmployeeController extends Controller
/** /**
* Remove the specified resource from storage. * Remove the specified resource from storage.
*/ */
public function destroy($id) public function destroy(Request $request)
{ {
try { try {
$employeeModel = $this->employeeRepository->getEmployeeById($id);
$employeeModel->user->roles()->detach(); $employeeModel = $this->employeeRepository->getEmployeeById($request->id);
$employeeModel->user->delete();
$employeeModel->delete(); optional($employeeModel)->user?->roles()?->detach();
optional($employeeModel)->user?->delete();
optional($employeeModel)->delete();
toastr()->success('Employee Delete Succesfully'); toastr()->success('Employee Delete Succesfully');
} catch (\Throwable $th) { } catch (\Throwable $th) {
toastr()->error($th->getMessage()); toastr()->error($th->getMessage());
} }
return redirect()->route('employee.index');
return response()->json(['status' => true, 'message' => 'Employee Delete Succesfully']);
} }
@ -153,4 +163,14 @@ class EmployeeController extends Controller
return redirect()->route('employee.index'); return redirect()->route('employee.index');
} }
public function changePassword(Request $request)
{
dd($request->all());
try {
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
}
} }

View File

@ -42,7 +42,8 @@
@forelse ($employees as $employee) @forelse ($employees as $employee)
<div class="col"> <div class="col">
<div class="card team-box ribbon-box mb-lg-0 material-shadow border shadow-none"> <div class="card team-box ribbon-box mb-lg-0 material-shadow border shadow-none">
<div class="team-cover"> <img src="assets/images/small/img-9.jpg" alt="" class="img-fluid"> <div class="team-cover">
<img src="{{ asset('assets/images/small/img-9.jpg') }}" alt="" class="img-fluid">
</div> </div>
<div class="card-body p-4"> <div class="card-body p-4">
@if ($employee->user) @if ($employee->user)
@ -69,9 +70,11 @@
<div class="col-lg-4 col"> <div class="col-lg-4 col">
<div class="team-profile-img"> <div class="team-profile-img">
<div class="avatar-lg img-thumbnail rounded-circle flex-shrink-0"><img <div class="img-thumbnail rounded-circle flex-shrink-0">
src="{{ asset('app/public/uploads/' . $employee->profile_picture) }}" alt="" <img style="height: 90px; width:90px; object-fit:cover"
class="member-img img-fluid d-block rounded-circle"></div> src="{{ asset($employee->profile_picture) }}" alt=""
class="img-fluid rounded-circle">
</div>
<div class="team-content"> <a class="member-name" <div class="team-content"> <a class="member-name"
href="{{ route('employee.show', $employee->id) }}"> href="{{ route('employee.show', $employee->id) }}">
<h5 class="fs-16 mb-1">{{ $employee->first_name }}</h5> <h5 class="fs-16 mb-1">{{ $employee->first_name }}</h5>

View File

@ -14,10 +14,16 @@ use Modules\Employee\Http\Controllers\EmployeeController;
| |
*/ */
Route::group(['middleware' => 'auth'], function () { Route::middleware('auth')->group(
Route::post('assignRole', [EmployeeController::class, 'assignRole'])->name('employee.assignRole'); function () {
Route::resource('employee', EmployeeController::class)->names('employee');
Route::group(['prefix' => 'employee'], function () { Route::prefix('employee')->as('employee.')->group(function () {
Route::post('assignRole', [EmployeeController::class, 'assignRole'])->name('assignRole');
Route::post('changePassword', [EmployeeController::class, 'changePassword'])->name('assignRole');
}); });
}); Route::resource('employee', EmployeeController::class)->names('employee');
}
);

16
app/Models/Branches.php Normal file
View File

@ -0,0 +1,16 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Branches extends Model
{
use HasFactory;
protected $table = "tbl_branches";
protected $primaryKey = "branch_id";
protected $guarded = [];
}

View File

@ -9,7 +9,7 @@ class Cities extends Model
{ {
use HasFactory; use HasFactory;
protected $table = 'tbl_citites'; protected $table = 'tbl_cities';
protected $primaryKey = 'city_id'; protected $primaryKey = 'city_id';
protected $guarded = []; protected $guarded = [];

View File

@ -15,19 +15,21 @@ class DatabaseSeeder extends Seeder
*/ */
public function run(): void public function run(): void
{ {
\App\Models\User::factory(10)->create(); // \App\Models\User::factory(10)->create();
$admin = \App\Models\User::factory()->create([ $admin = \App\Models\User::factory()->create([
'name' => 'Admin User', 'name' => 'Admin User',
'email' => 'admin@gmail.com', 'email' => 'admin@gmail.com',
'password' => Hash::make('password'), 'employee_id' => 1,
'password' => bcrypt('password'),
]); ]);
$member = \App\Models\User::factory()->create([ $member = \App\Models\User::factory()->create([
'name' => 'Member User', 'name' => 'Member User',
'email' => 'member@gmail.com', 'email' => 'member@gmail.com',
'password' => Hash::make('password'), 'employee_id' => 2,
'password' => bcrypt('password'),
]); ]);

View File

@ -24,7 +24,9 @@ $('body').on('click', '.remove-item-btn', function (e) {
id: id id: id
}, },
success: function (response) { success: function (response) {
if(response.status == true){
location.reload(); location.reload();
}
}, },
error: function (xhr, status, error) { error: function (xhr, status, error) {
console.error(xhr.responseText); console.error(xhr.responseText);

View File

@ -1,30 +1,47 @@
@extends('layouts.app') @extends('layouts.app')
@section('content') @section('content')
<div class='card'> <div class="page-content">
<div class='card-header d-flex justify-content-between align-items-center'> <div class="container-fluid">
<h2 class="">{{ label('Add Cities') }}</h2>
<?php createButton('btn-primary btn-cancel', '', 'Cancel', route('cities.index')); ?>
</div> <!-- start page title -->
@include('layouts.partials.breadcrumb', ['title' => 'City'])
<!-- end page title -->
<div class='card'>
<div class='card-body'> <div class='card-body'>
<form action="{{ $editable ? route('cities.update', [$data->city_id]) : route('cities.store') }}" id="updateCustomForm" <form action="{{ $editable ? route('cities.update', [$data->city_id]) : route('cities.store') }}"
method="POST"> id="updateCustomForm" method="POST">
@csrf <input type=hidden name='city_id' value='{{ $editable ? $data->city_id : '' }}' />
@csrf
<input type=hidden name='city_id' value='{{ $editable ? $data->city_id : '' }}' />
<div class="row"> <div class="row">
<div class="col-lg-6"> <div class="col-lg-6">
{{ createCustomSelect('tbl_districts', 'title', 'district_id', $editable ? $data->districts_id : '', 'Districts Id', 'districts_id', 'form-control select2', 'status<>-1') }} {{ createText('title', 'title', 'Title', '', $editable ? $data->title : '') }}
</div> </div>
<div class="col-lg-6">{{ createText('title', 'title', 'Title', '', $editable ? $data->title : '') }}
<div class="col-lg-6">
{{ createCustomSelect('tbl_districts', 'title', 'district_id', $editable ? $data->districts_id : '', 'District', 'districts_id', 'form-control select2', 'status<>-1') }}
</div> </div>
<div class="col-lg-12 pb-2">
{{-- <div class="col-lg-12 pb-2">
{{ createTextarea('description', 'description ckeditor-classic', 'Description', $editable ? $data->description : '') }} {{ createTextarea('description', 'description ckeditor-classic', 'Description', $editable ? $data->description : '') }}
</div> --}}
<div class="col-lg-12 pb-2">
{{ createPlainTextArea('remarks', '', 'Remarks', $editable ? $data->remarks : '') }}
</div> </div>
<div class="col-lg-12 pb-2">{{ createPlainTextArea('remarks', '', 'Remarks', $editable ? $data->remarks : '') }}
</div> <div class="col-md-12 mt-2">
<div class="col-md-12"><?php createButton('btn-primary btn-update', '', 'Submit'); ?> <?php createButton('btn-primary btn-update', '', 'Submit'); ?>
<?php createButton('btn-primary btn-cancel', '', 'Cancel', route('cities.index')); ?> <?php createButton('btn-danger btn-cancel', '', 'Cancel', route('cities.index')); ?>
</div> </div>
</form> </form>
</div> </div>
</div> </div>
</div>
</div>
@endsection @endsection

View File

@ -1,30 +1,39 @@
@extends('layouts.app') @extends('layouts.app')
@section('content') @section('content')
<div class="page-content">
<div class="container-fluid">
<!-- start page title -->
@include('layouts.partials.breadcrumb', ['title' => 'City'])
<!-- end page title -->
<div class="card"> <div class="card">
<div class="card-header d-flex justify-content-between align-items-center"> <div class="card-header align-items-center d-flex">
<h2>{{ label('Cities List') }}</h2> <h5 class="card-title flex-grow-1 mb-0">City Lists</h5>
<a href="{{ route('cities.create') }}" class="btn btn-primary"><span>{{ label('Create New') }}</span></a> <div class="flex-shrink-0">
<a href="{{ route('cities.create') }}" class="btn btn-success waves-effect waves-light"><i
class="ri-add-fill me-1 align-bottom"></i> Create City</a>
</div> </div>
</div>
<div class="card-body"> <div class="card-body">
<table class="dataTable table" id="tbl_cities" data-url="{{ route('cities.sort') }}"> <table class="dataTable table" id="tbl_cities" data-url="{{ route('cities.sort') }}">
<thead class="table-light"> <thead class="table-light">
<tr> <tr>
<th class="tb-col"><span class="overline-title">{{ label('Sn.') }}</span></th> <th class="tb-col"><span class="overline-title">{{ label('Sn.') }}</span></th>
<th class="tb-col"><span class="overline-title">{{ label('districts') }}</span></th> <th class="tb-col"><span class="overline-title">{{ label('District') }}</span></th>
<th class="tb-col"><span class="overline-title">{{ label('title') }}</span></th> <th class="tb-col"><span class="overline-title">{{ label('title') }}</span></th>
<th class="tb-col"><span class="overline-title">{{ label('alias') }}</span></th> <th class="tb-col"><span class="overline-title">{{ label('alias') }}</span></th>
<th class="tb-col" data-sortable="false"><span class="overline-title">{{ label('Action') }}</span> <th class="tb-col" data-sortable="false"><span class="overline-title">{{ label('Action') }}</span>
</th> </th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@php
$i = 1;
@endphp
@foreach ($data as $item) @foreach ($data as $item)
<tr data-id="{{ $item->city_id }}" data-display_order="{{ $item->display_order }}" <tr data-id="{{ $item->city_id }}" data-display_order="{{ $item->display_order }}"
class="draggable-row <?php echo $item->status == 0 ? 'bg-light bg-danger' : ''; ?>"> class="draggable-row <?php echo $item->status == 0 ? 'bg-light bg-danger' : ''; ?>">
<td class="tb-col">{{ $i++ }}</td> <td class="tb-col">{{ $index + 1 }}</td>
<td class="tb-col"> <td class="tb-col">
{!! getFieldData('tbl_districts', 'title', 'district_id', $item->districts_id) !!} {!! getFieldData('tbl_districts', 'title', 'district_id', $item->districts_id) !!}
</td> </td>
@ -54,7 +63,6 @@
<i class="ri-article-fill text-muted me-2 align-bottom"></i> <i class="ri-article-fill text-muted me-2 align-bottom"></i>
{{ $item->status == 1 ? label('Unpublish') : label('Publish') }} {{ $item->status == 1 ? label('Unpublish') : label('Publish') }}
</a> </a>
</li> </li>
<li> <li>
<a href="{{ route('cities.clone', [$item->city_id]) }}" class="dropdown-item toggle-item-btn" <a href="{{ route('cities.clone', [$item->city_id]) }}" class="dropdown-item toggle-item-btn"
@ -68,38 +76,22 @@
onclick="confirmDelete(this.href)"> onclick="confirmDelete(this.href)">
<i class="ri-delete-bin-fill text-muted me-2 align-bottom"></i> {{ label('Delete') }} <i class="ri-delete-bin-fill text-muted me-2 align-bottom"></i> {{ label('Delete') }}
</a> </a>
</li> </li>
</ul> </ul>
</div> </div>
</td> </td>
</tr> </tr>
@endforeach @endforeach
</tbody> </tbody>
</table> </table>
</div>
</div>
</div> </div>
</div> </div>
@endsection @endsection
@push('css')
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.5/css/dataTables.bootstrap4.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/rowreorder/1.4.0/css/rowReorder.dataTables.min.css">
@endpush
@push('js') @push('js')
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.68/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.68/vfs_fonts.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.13.5/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.4.1/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/rowreorder/1.4.0/js/dataTables.rowReorder.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script> <script>
$(document).ready(function(e) { $(document).ready(function(e) {
$('.change-alias-badge').on('click', function() { $('.change-alias-badge').on('click', function() {

View File

@ -1,17 +1,17 @@
<?php <?php
use App\Http\Controllers\DistrictsController; use App\Http\Controllers\DistrictsController;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
Route::prefix("districts")->group(function () { Route::prefix("district")->as('districts.')->group(function () {
Route::get('/', [DistrictsController::class, 'index'])->name('districts.index'); Route::get('/', [DistrictsController::class, 'index'])->name('index');
Route::get('/create', [DistrictsController::class, 'create'])->name('districts.create'); Route::get('/create', [DistrictsController::class, 'create'])->name('create');
Route::post('/store', [DistrictsController::class, 'store'])->name('districts.store'); Route::post('/store', [DistrictsController::class, 'store'])->name('store');
Route::post('/sort', [DistrictsController::class, 'sort'])->name('districts.sort'); Route::post('/sort', [DistrictsController::class, 'sort'])->name('sort');
Route::post('/updatealias', [DistrictsController::class, 'updatealias'])->name('districts.updatealias'); Route::post('/updatealias', [DistrictsController::class, 'updatealias'])->name('updatealias');
Route::get('/show/{id}', [DistrictsController::class, 'show'])->name('districts.show'); Route::get('/show/{id}', [DistrictsController::class, 'show'])->name('show');
Route::get('/edit/{id}', [DistrictsController::class, 'edit'])->name('districts.edit') ; Route::get('/edit/{id}', [DistrictsController::class, 'edit'])->name('edit') ;
Route::post('/update/{id}', [DistrictsController::class, 'update'])->name('districts.update'); Route::post('/update/{id}', [DistrictsController::class, 'update'])->name('update');
Route::delete('/destroy/{id}', [DistrictsController::class, 'destroy'])->name('districts.destroy'); Route::delete('/destroy/{id}', [DistrictsController::class, 'destroy'])->name('destroy');
Route::get('/toggle/{id}', [DistrictsController::class, 'toggle'])->name('districts.toggle'); Route::get('/toggle/{id}', [DistrictsController::class, 'toggle'])->name('toggle');
Route::get('/clone/{id}', [DistrictsController::class, 'clone'])->name('districts.clone'); Route::get('/clone/{id}', [DistrictsController::class, 'clone'])->name('clone');
}); });

View File

@ -1,9 +1,8 @@
<?php <?php
use App\Http\Controllers\PermissionController; use App\Http\Controllers\PermissionController;
use App\Http\Controllers\RoleController;
use App\Http\Controllers\UserController;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use Modules\User\Http\Controllers\RoleController;
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
@ -50,14 +49,14 @@ Route::middleware('auth')->group(function () {
require __DIR__ . '/CRUDgenerated/route.districts.php'; require __DIR__ . '/CRUDgenerated/route.districts.php';
require __DIR__ . '/CRUDgenerated/route.cities.php'; require __DIR__ . '/CRUDgenerated/route.cities.php';
require __DIR__ . '/CRUDgenerated/route.vendortypes.php'; // require __DIR__ . '/CRUDgenerated/route.vendortypes.php';
require __DIR__ . '/CRUDgenerated/route.vendors.php'; // require __DIR__ . '/CRUDgenerated/route.vendors.php';
require __DIR__ . '/CRUDgenerated/route.genders.php'; // require __DIR__ . '/CRUDgenerated/route.genders.php';
require __DIR__ . '/CRUDgenerated/route.castes.php'; // require __DIR__ . '/CRUDgenerated/route.castes.php';
require __DIR__ . '/CRUDgenerated/route.nationalities.php'; // require __DIR__ . '/CRUDgenerated/route.nationalities.php';
require __DIR__ . '/CRUDgenerated/route.ethnicities.php'; // require __DIR__ . '/CRUDgenerated/route.ethnicities.php';
require __DIR__ . '/CRUDgenerated/route.dags.php'; // require __DIR__ . '/CRUDgenerated/route.dags.php';
// require __DIR__ . '/CRUDgenerated/route.employees.php'; // require __DIR__ . '/CRUDgenerated/route.employees.php';