diff --git a/Modules/Employee/app/Models/Employee.php b/Modules/Employee/app/Models/Employee.php index 71d31d3..076c097 100644 --- a/Modules/Employee/app/Models/Employee.php +++ b/Modules/Employee/app/Models/Employee.php @@ -10,6 +10,12 @@ class Employee extends Model protected $table = 'tbl_employees'; protected $primaryKey = 'id'; protected $guarded = []; + protected $appends = (['full_name']); + + protected function getFullNameAttribute() + { + return $this->first_name . ' ' . $this->middle_name . ' ' . $this->last_name; + } public function user() { diff --git a/Modules/Employee/app/Repositories/EmployeeInterface.php b/Modules/Employee/app/Repositories/EmployeeInterface.php index e31844d..4f80cb3 100644 --- a/Modules/Employee/app/Repositories/EmployeeInterface.php +++ b/Modules/Employee/app/Repositories/EmployeeInterface.php @@ -10,4 +10,6 @@ interface EmployeeInterface public function delete($employeeId); public function create($EmployeeDetails); public function update($employeeId, array $newDetails); + public function pluck(); + } diff --git a/Modules/Employee/app/Repositories/EmployeeRepository.php b/Modules/Employee/app/Repositories/EmployeeRepository.php index ee32a5e..d244e2d 100644 --- a/Modules/Employee/app/Repositories/EmployeeRepository.php +++ b/Modules/Employee/app/Repositories/EmployeeRepository.php @@ -8,7 +8,7 @@ class EmployeeRepository implements EmployeeInterface { public function findAll() { - return Employee::with('user.roles')->paginate(20); + return Employee::paginate(20); } public function getEmployeeById($employeeId) @@ -36,6 +36,11 @@ class EmployeeRepository implements EmployeeInterface return Employee::whereId($employeeId)->update($newDetails); } + public function pluck() + { + return Employee::pluck('first_name', 'id'); + } + // public function uploadImage($file) // { // if ($req->file()) { diff --git a/Modules/Employee/routes/web.php b/Modules/Employee/routes/web.php index 45acc1c..0ffff23 100644 --- a/Modules/Employee/routes/web.php +++ b/Modules/Employee/routes/web.php @@ -21,3 +21,5 @@ Route::group(['middleware' => 'auth'], function () { }); }); + + diff --git a/Modules/Leave/app/Http/Controllers/LeaveController.php b/Modules/Leave/app/Http/Controllers/LeaveController.php index 92e4447..236e547 100644 --- a/Modules/Leave/app/Http/Controllers/LeaveController.php +++ b/Modules/Leave/app/Http/Controllers/LeaveController.php @@ -5,16 +5,19 @@ namespace Modules\Leave\Http\Controllers; use App\Http\Controllers\Controller; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Modules\Employee\Repositories\EmployeeInterface; use Modules\Leave\Repositories\LeaveInterface; use Yoeunes\Toastr\Facades\Toastr; class LeaveController extends Controller { - private LeaveInterface $leaveRepository; + private $leaveRepository; + private $employeeRepository; - public function __construct(LeaveInterface $leaveRepository) + public function __construct(LeaveInterface $leaveRepository, EmployeeInterface $employeeRepository) { $this->leaveRepository = $leaveRepository; + $this->employeeRepository = $employeeRepository; $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']]); @@ -29,8 +32,9 @@ class LeaveController extends Controller public function index() { $data['leaves'] = $this->leaveRepository->findAll(); - - return view('leave::index',$data); + $data['employeeList'] = $this->employeeRepository->pluck(); + + return view('leave::index', $data); } /** @@ -39,7 +43,7 @@ class LeaveController extends Controller public function create() { $data['title'] = 'Create Leave'; - + $data['employeeList'] = $this->employeeRepository->pluck(); return view('leave::create', $data); } @@ -49,13 +53,9 @@ class LeaveController extends Controller public function store(Request $request): RedirectResponse { $inputData = $request->all(); - try { - $this->leaveRepository->create($inputData); - toastr()->success('Leave Created Succesfully'); - } catch (\Throwable $th) { toastr()->error($th->getMessage()); } @@ -79,7 +79,7 @@ class LeaveController extends Controller $data['leave'] = $this->leaveRepository->getLeaveById($id); - return view('leave::edit',$data); + return view('leave::edit', $data); } /** diff --git a/Modules/Leave/resources/views/edit.blade.php b/Modules/Leave/resources/views/edit.blade.php index 37dd0f4..4644d7c 100644 --- a/Modules/Leave/resources/views/edit.blade.php +++ b/Modules/Leave/resources/views/edit.blade.php @@ -24,7 +24,7 @@