StocksNew/Modules/Admin/app/Http/Controllers/ResignationController.php
Sampanna Rimal 53c0140f58 first commit
2024-08-27 17:48:06 +05:45

105 lines
3.0 KiB
PHP

<?php
namespace Modules\Admin\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Modules\Admin\Repositories\ResignationRepository;
use Modules\Employee\Repositories\EmployeeRepository;
class ResignationController extends Controller
{
private $resignationRepository;
private $employeeRepository;
public function __construct(ResignationRepository $resignationRepository, EmployeeRepository $employeeRepository)
{
$this->resignationRepository = $resignationRepository;
$this->employeeRepository = $employeeRepository;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = 'Resignation Lists';
$data['resignationLists'] = $this->resignationRepository->findAll();
return view('admin::resignations.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Resignation';
$data['editable'] = false;
$data['employeeLists'] = $this->employeeRepository->pluck();
return view('admin::resignations.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
try {
$this->resignationRepository->create($request->all());
toastr()->success('Resignation has been created!');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
// return redirect()->route('resignation.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('admin::resignations.show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit Resignation';
$data['editable'] = true;
$data['employeeLists'] = $this->employeeRepository->pluck();
$data['resignation'] = $this->resignationRepository->getResignationById($id);
return view('admin::resignations.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
try {
$this->resignationRepository->update($id, $request->except(['_method', '_token']));
toastr()->success('Resignation has been updated!');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('resignation.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$this->resignationRepository->delete($id);
toastr()->success('Resignation has been deleted');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return to_route('resignation.index');
}
}