employee module
This commit is contained in:
@ -5,15 +5,24 @@ namespace Modules\Employee\Http\Controllers;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Employee\Repositories\EmployeeInterface;
|
||||
|
||||
class EmployeeController extends Controller
|
||||
{
|
||||
|
||||
private EmployeeInterface $employeeRepository;
|
||||
|
||||
public function __construct(EmployeeInterface $employeeRepository)
|
||||
{
|
||||
$this->employeeRepository = $employeeRepository;
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('employee::index');
|
||||
$data['employees'] = $this->employeeRepository->findAll();
|
||||
return view('employee::index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -28,9 +37,25 @@ class EmployeeController extends Controller
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
$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');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,6 +63,7 @@ class EmployeeController extends Controller
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
|
||||
return view('employee::show');
|
||||
}
|
||||
|
||||
@ -46,7 +72,9 @@ class EmployeeController extends Controller
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return view('employee::edit');
|
||||
$data['title'] = 'Edit Employee';
|
||||
$data['employee'] = $this->employeeRepository->getEmployeeById($id);
|
||||
return view('employee::edit', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,7 +82,21 @@ class EmployeeController extends Controller
|
||||
*/
|
||||
public function update(Request $request, $id): RedirectResponse
|
||||
{
|
||||
//
|
||||
$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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user