New-OMIS/Modules/Leave/app/Http/Controllers/LeaveController.php

101 lines
2.7 KiB
PHP
Raw Normal View History

2024-04-05 04:33:35 +00:00
<?php
namespace Modules\Leave\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Leave\Repositories\LeaveInterface;
2024-04-05 12:11:16 +00:00
use Yoeunes\Toastr\Facades\Toastr;
2024-04-05 04:33:35 +00:00
class LeaveController extends Controller
{
private LeaveInterface $leaveRepository;
public function __construct(LeaveInterface $leaveRepository)
{
$this->leaveRepository = $leaveRepository;
2024-04-05 12:11:16 +00:00
$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']]);
2024-04-05 04:33:35 +00:00
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['leaves'] = $this->leaveRepository->findAll();
2024-04-05 12:11:16 +00:00
return view('leave::index',$data);
2024-04-05 04:33:35 +00:00
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Leave';
return view('leave::create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$inputData = $request->all();
try {
$this->leaveRepository->create($inputData);
2024-04-05 12:11:16 +00:00
Toastr()->success('Leave Created Succesfully');
2024-04-05 04:33:35 +00:00
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('leave.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('leave::show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
2024-04-05 12:11:16 +00:00
$data['title'] = 'Edit Leave';
$data['leave'] = $this->leaveRepository->getLeaveById($id);
return view('leave::edit',$data);
2024-04-05 04:33:35 +00:00
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
2024-04-05 12:11:16 +00:00
$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');
2024-04-05 04:33:35 +00:00
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
2024-04-05 12:11:16 +00:00
$this->leaveRepository->delete($id);
toastr()->success('Leave Deleted Succesfully');
2024-04-05 04:33:35 +00:00
}
}