2024-04-04 12:19:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Modules\Employee\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Illuminate\Http\Request;
|
2024-04-07 11:54:18 +00:00
|
|
|
use Modules\Employee\Repositories\EmployeeInterface;
|
2024-04-04 12:19:56 +00:00
|
|
|
|
|
|
|
class EmployeeController extends Controller
|
|
|
|
{
|
2024-04-07 11:54:18 +00:00
|
|
|
|
|
|
|
private EmployeeInterface $employeeRepository;
|
|
|
|
|
|
|
|
public function __construct(EmployeeInterface $employeeRepository)
|
|
|
|
{
|
|
|
|
$this->employeeRepository = $employeeRepository;
|
|
|
|
}
|
2024-04-04 12:19:56 +00:00
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
2024-04-07 11:54:18 +00:00
|
|
|
$data['employees'] = $this->employeeRepository->findAll();
|
|
|
|
return view('employee::index', $data);
|
2024-04-04 12:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
2024-04-07 07:58:06 +00:00
|
|
|
$data['title'] = 'Create Employee';
|
|
|
|
return view('employee::create', $data);
|
2024-04-04 12:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*/
|
2024-04-07 11:54:18 +00:00
|
|
|
public function store(Request $request)
|
2024-04-04 12:19:56 +00:00
|
|
|
{
|
2024-04-07 11:54:18 +00:00
|
|
|
$inputData = $request->only(['first_name', 'last_name']);
|
|
|
|
// try {
|
|
|
|
|
|
|
|
if ($request->hasFile('profile_pic')) {
|
|
|
|
$fileName = time() . '_' . $request->profile_pic->getClientOriginalName();
|
|
|
|
$filePath = $request->file('profile_pic')->storeAs('uploads', $fileName, 'public');
|
|
|
|
$inputData['profile_picture'] = time() . '_' . $request->profile_pic->getClientOriginalName();
|
|
|
|
// $fileModel->file_path = '/storage/' . $filePath;
|
|
|
|
// $fileModel->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->employeeRepository->create($inputData);
|
|
|
|
toastr()->success('Employee Created Succesfully');
|
|
|
|
// } catch (\Throwable $th) {
|
|
|
|
// toastr()->error($th->getMessage());
|
|
|
|
// }
|
|
|
|
return redirect()->route('employee.index');
|
2024-04-04 12:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the specified resource.
|
|
|
|
*/
|
|
|
|
public function show($id)
|
|
|
|
{
|
2024-04-07 11:54:18 +00:00
|
|
|
|
2024-04-04 12:19:56 +00:00
|
|
|
return view('employee::show');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
2024-04-07 11:54:18 +00:00
|
|
|
$data['title'] = 'Edit Employee';
|
|
|
|
$data['employee'] = $this->employeeRepository->getEmployeeById($id);
|
|
|
|
return view('employee::edit', $data);
|
2024-04-04 12:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*/
|
|
|
|
public function update(Request $request, $id): RedirectResponse
|
|
|
|
{
|
2024-04-07 11:54:18 +00:00
|
|
|
$inputData = $request->only(['first_name', 'last_name']);
|
|
|
|
// try {
|
|
|
|
|
|
|
|
if ($request->hasFile('profile_pic')) {
|
|
|
|
$fileName = time() . '_' . $request->profile_pic->getClientOriginalName();
|
|
|
|
$filePath = $request->file('profile_pic')->storeAs('uploads', $fileName, 'public');
|
|
|
|
$inputData['profile_picture'] = time() . '_' . $request->profile_pic->getClientOriginalName();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->employeeRepository->update($id, $inputData);
|
|
|
|
toastr()->success('Employee Created Succesfully');
|
|
|
|
// } catch (\Throwable $th) {
|
|
|
|
// toastr()->error($th->getMessage());
|
|
|
|
// }
|
|
|
|
return redirect()->route('employee.index');
|
2024-04-04 12:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*/
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|