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

95 lines
2.7 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\AppreciationRepository;
use Modules\Employee\Repositories\EmployeeRepository;
class AppreciationController extends Controller
{
private $appreciationRepository;
private $employeeRepository;
public function __construct(AppreciationRepository $appreciationRepository, EmployeeRepository $employeeRepository)
{
$this->appreciationRepository = $appreciationRepository;
$this->employeeRepository = $employeeRepository;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = "Appreciation Lists";
$data['appreciationLists'] = $this->appreciationRepository->findAll();
return view('admin::appreciations.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = "Create Appreciation";
$data['editable'] = false;
$data['employeeLists'] = $this->employeeRepository->pluck();
return view('admin::appreciations.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
try {
$this->appreciationRepository->create($request->all());
toastr()->success('Appreciation Created Successfully.');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('appreciation.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('admin::appreciations.show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = "Edit Appreciation";
$data['editable'] = true;
$data['employeeLists'] = $this->employeeRepository->pluck();
$data['appreciation'] = $this->appreciationRepository->getAppreciationById($id);
return view('admin::appreciations.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$this->appreciationRepository->update($id, $request->all());
toastr()->success('Appreciation Updated Successfully.');
return redirect()->route('appreciation.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
//
}
}