diff --git a/Modules/Employee/Http/Controllers/.gitkeep b/Modules/Employee/app/Http/Controllers/.gitkeep similarity index 100% rename from Modules/Employee/Http/Controllers/.gitkeep rename to Modules/Employee/app/Http/Controllers/.gitkeep diff --git a/Modules/Employee/Http/Controllers/EmployeeController.php b/Modules/Employee/app/Http/Controllers/EmployeeController.php similarity index 100% rename from Modules/Employee/Http/Controllers/EmployeeController.php rename to Modules/Employee/app/Http/Controllers/EmployeeController.php diff --git a/Modules/Employee/Models/.gitkeep b/Modules/Employee/app/Models/.gitkeep similarity index 100% rename from Modules/Employee/Models/.gitkeep rename to Modules/Employee/app/Models/.gitkeep diff --git a/Modules/Employee/app/Models/Employee.php b/Modules/Employee/app/Models/Employee.php new file mode 100644 index 0000000..7002cf2 --- /dev/null +++ b/Modules/Employee/app/Models/Employee.php @@ -0,0 +1,13 @@ +app->bind(EmployeeInterface::class, EmployeeRepository::class); $this->app->register(RouteServiceProvider::class); } diff --git a/Modules/Employee/Providers/RouteServiceProvider.php b/Modules/Employee/app/Providers/RouteServiceProvider.php similarity index 100% rename from Modules/Employee/Providers/RouteServiceProvider.php rename to Modules/Employee/app/Providers/RouteServiceProvider.php diff --git a/Modules/Employee/Repositories/.gitkeep b/Modules/Employee/app/Repositories/.gitkeep similarity index 100% rename from Modules/Employee/Repositories/.gitkeep rename to Modules/Employee/app/Repositories/.gitkeep diff --git a/Modules/Employee/app/Repositories/EmployeeInterface.php b/Modules/Employee/app/Repositories/EmployeeInterface.php new file mode 100644 index 0000000..947e916 --- /dev/null +++ b/Modules/Employee/app/Repositories/EmployeeInterface.php @@ -0,0 +1,12 @@ +update($newDetails); + } + +} diff --git a/Modules/Leave/app/Http/Controllers/LeaveController.php b/Modules/Leave/app/Http/Controllers/LeaveController.php index 7f65e29..3ca1131 100644 --- a/Modules/Leave/app/Http/Controllers/LeaveController.php +++ b/Modules/Leave/app/Http/Controllers/LeaveController.php @@ -6,6 +6,7 @@ use App\Http\Controllers\Controller; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Modules\Leave\Repositories\LeaveInterface; +use Yoeunes\Toastr\Facades\Toastr; class LeaveController extends Controller { @@ -14,6 +15,12 @@ class LeaveController extends Controller public function __construct(LeaveInterface $leaveRepository) { $this->leaveRepository = $leaveRepository; + + $this->middleware('role_or_permission:access leaves|create leaves|edit leaves|delete leaves', ['only' => ['index', 'show']]); + $this->middleware('role_or_permission:create leaves', ['only' => ['create', 'store']]); + $this->middleware('role_or_permission:edit leaves', ['only' => ['edit', 'update']]); + $this->middleware('role_or_permission:delete leaves', ['only' => ['destroy']]); + } /** @@ -22,8 +29,7 @@ class LeaveController extends Controller public function index() { $data['leaves'] = $this->leaveRepository->findAll(); - // dd($data['leaves']); - return view('leave::index'); + return view('leave::index',$data); } /** @@ -43,7 +49,7 @@ class LeaveController extends Controller $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()); } @@ -63,7 +69,9 @@ class LeaveController extends Controller */ public function edit($id) { - return view('leave::edit'); + $data['title'] = 'Edit Leave'; + $data['leave'] = $this->leaveRepository->getLeaveById($id); + return view('leave::edit',$data); } /** @@ -71,7 +79,14 @@ class LeaveController extends Controller */ public function update(Request $request, $id): RedirectResponse { - // + $inputData = $request->all(); + try { + $this->leaveRepository->update($id,$inputData); + toastr()->success('Leave Updated Succesfully'); + } catch (\Throwable $th) { + toastr()->error($th->getMessage()); + } + return redirect()->route('leave.index'); } /** @@ -79,6 +94,7 @@ class LeaveController extends Controller */ public function destroy($id) { - // + $this->leaveRepository->delete($id); + toastr()->success('Leave Deleted Succesfully'); } } diff --git a/Modules/Leave/app/Models/Leave.php b/Modules/Leave/app/Models/Leave.php index 48f2185..c691311 100644 --- a/Modules/Leave/app/Models/Leave.php +++ b/Modules/Leave/app/Models/Leave.php @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model; class Leave extends Model { protected $table = 'leaves'; + protected $primaryKey = 'leave_id'; protected $guarded = []; } diff --git a/Modules/Leave/app/Repositories/LeaveRepository.php b/Modules/Leave/app/Repositories/LeaveRepository.php index abdb3a5..e62b14f 100644 --- a/Modules/Leave/app/Repositories/LeaveRepository.php +++ b/Modules/Leave/app/Repositories/LeaveRepository.php @@ -28,7 +28,7 @@ class LeaveRepository implements LeaveInterface public function update($leaveId, array $newDetails) { - return Leave::whereId($leaveId)->update($newDetails); + return Leave::where('leave_id',$leaveId)->update($newDetails); } } diff --git a/Modules/Leave/resources/views/edit.blade.php b/Modules/Leave/resources/views/edit.blade.php new file mode 100644 index 0000000..67912e4 --- /dev/null +++ b/Modules/Leave/resources/views/edit.blade.php @@ -0,0 +1,47 @@ +@extends('layouts.app') + +@section('content') +
+
+ +
+
+
+

{{ $title }}

+ +
+ +
+ +
+
+
+ +
+
+
+
+
+ @csrf + @method('put') + + @include('leave::partials.action') +
+
+
+
+
+ + +
+ +
+@endsection + +@push('js') + +@endpush diff --git a/Modules/Leave/resources/views/index.blade.php b/Modules/Leave/resources/views/index.blade.php index 82f6cc4..0aab2c4 100644 --- a/Modules/Leave/resources/views/index.blade.php +++ b/Modules/Leave/resources/views/index.blade.php @@ -49,250 +49,97 @@
Leave Lists
- Add
- +
- - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @forelse ($leaves as $key => $leave) + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + @empty + @endforelse +
NamePositionOfficeAgeStart dateSalaryS.NEmployee NameStart DateEnd DateCreated AtAction
Tiger NixonSystem ArchitectEdinburgh612011/04/25$320,800
Garrett WintersAccountantTokyo632011/07/25$170,750
Ashton CoxJunior Technical AuthorSan Francisco662009/01/12$86,000
Cedric KellySenior Javascript DeveloperEdinburgh222012/03/29$433,060
Airi SatouAccountantTokyo332008/11/28$162,700
Brielle WilliamsonIntegration SpecialistNew York612012/12/02$372,000
Herrod ChandlerSales AssistantSan Francisco592012/08/06$137,500
Rhona DavidsonIntegration SpecialistTokyo552010/10/14$327,900
Colleen HurstJavascript DeveloperSan Francisco392009/09/15$205,500
Sonya FrostSoftware EngineerEdinburgh232008/12/13$103,600
Jena GainesOffice ManagerLondon302008/12/19$90,560
Quinn FlynnSupport LeadEdinburgh222013/03/03$342,000
Charde MarshallRegional DirectorSan Francisco362008/10/16$470,600
Haley KennedySenior Marketing DesignerLondon432012/12/18$313,500
Tatyana FitzpatrickRegional DirectorLondon192010/03/17$385,750
Michael SilvaMarketing DesignerLondon662012/11/27$198,500
Paul ByrdChief Financial Officer (CFO)New York642010/06/09$725,000
Gloria LittleSystems AdministratorNew York592009/04/10$237,500
Bradley GreerSoftware EngineerLondon412012/10/13$132,000
Dai RiosPersonnel LeadEdinburgh352012/09/26$217,500
Jenette CaldwellDevelopment LeadNew York302011/09/03$345,000
Yuri BerryChief Marketing Officer (CMO)New York402009/06/25$675,000
Caesar VancePre-Sales SupportNew York212011/12/12$106,450
Doris WilderSales AssistantSydney232010/09/20$85,600
{{ $key + 1 }}{{ $leave->employee_id }}{{ $leave->start_date }}{{ $leave->end_date }}{{ $leave->created_at }} +
+ + + + -
Gavin CortezTeam LeaderSan Francisco222008/10/26$235,500
Martena MccrayPost-Sales supportEdinburgh462011/03/09$324,050
Unity ButlerMarketing DesignerSan Francisco472009/12/09$85,675
- + @include('leave::partials.view') @endsection + +@push('js') + +@endpush diff --git a/Modules/Leave/resources/views/partials/action.blade.php b/Modules/Leave/resources/views/partials/action.blade.php index 4c674da..c9219f4 100644 --- a/Modules/Leave/resources/views/partials/action.blade.php +++ b/Modules/Leave/resources/views/partials/action.blade.php @@ -1,30 +1,38 @@
- - -
- Please enter employee name. + + +
+ Please enter employee name.
+{{--
+ + +
--}} +
- - + +
+
- - + +
+ +{{--
- - -
-
- - -
+ + +
--}} +
- +
@push('js') - + @endpush diff --git a/Modules/Leave/resources/views/partials/view.blade.php b/Modules/Leave/resources/views/partials/view.blade.php new file mode 100644 index 0000000..c17e8df --- /dev/null +++ b/Modules/Leave/resources/views/partials/view.blade.php @@ -0,0 +1,16 @@ + diff --git a/Modules/Leave/resources/views/show.blade.php b/Modules/Leave/resources/views/show.blade.php new file mode 100644 index 0000000..e69de29 diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 03b0033..a65405e 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -15,7 +15,7 @@ class DatabaseSeeder extends Seeder */ public function run(): void { - // \App\Models\User::factory(10)->create(); + \App\Models\User::factory(10)->create(); $admin = \App\Models\User::factory()->create([ 'name' => 'Admin User', @@ -34,10 +34,10 @@ class DatabaseSeeder extends Seeder $adminRole = Role::create(['name' => 'admin']); $memberRole = Role::create(['name' => 'member']); - $permission = Permission::create(['name' => 'create products']); - $permission = Permission::create(['name' => 'access products']); - $permission = Permission::create(['name' => 'edit products']); - $permission = Permission::create(['name' => 'delete products']); + $permission = Permission::create(['name' => 'create leaves']); + $permission = Permission::create(['name' => 'access leaves']); + $permission = Permission::create(['name' => 'edit leaves']); + $permission = Permission::create(['name' => 'delete leaves']); $permission = Permission::create(['name' => 'access roles']); $permission = Permission::create(['name' => 'edit roles']); diff --git a/database/seeders/PermissionSeeder.php b/database/seeders/PermissionSeeder.php new file mode 100644 index 0000000..d4f82f0 --- /dev/null +++ b/database/seeders/PermissionSeeder.php @@ -0,0 +1,36 @@ + 'create leaves']); + $permission = Permission::create(['name' => 'access leaves']); + $permission = Permission::create(['name' => 'edit leaves']); + $permission = Permission::create(['name' => 'delete leaves']); + + $permission = Permission::create(['name' => 'access roles']); + $permission = Permission::create(['name' => 'edit roles']); + $permission = Permission::create(['name' => 'create roles']); + $permission = Permission::create(['name' => 'delete roles']); + + $permission = Permission::create(['name' => 'access users']); + $permission = Permission::create(['name' => 'edit users']); + $permission = Permission::create(['name' => 'create users']); + $permission = Permission::create(['name' => 'delete users']); + + $permission = Permission::create(['name' => 'access permissions']); + $permission = Permission::create(['name' => 'edit permissions']); + $permission = Permission::create(['name' => 'create permissions']); + $permission = Permission::create(['name' => 'delete permissions']); + } +}