first commit
This commit is contained in:
0
Modules/Employee/app/Repositories/.gitkeep
Normal file
0
Modules/Employee/app/Repositories/.gitkeep
Normal file
16
Modules/Employee/app/Repositories/EmployeeInterface.php
Normal file
16
Modules/Employee/app/Repositories/EmployeeInterface.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Employee\Repositories;
|
||||
use Modules\Employee\Models\Employee;
|
||||
|
||||
interface EmployeeInterface
|
||||
{
|
||||
public function findAll();
|
||||
public function getEmployeeById($employeeId);
|
||||
public function getEmployeeByEmail($email);
|
||||
public function delete($employeeId);
|
||||
public function create($EmployeeDetails);
|
||||
public function update($employeeId, array $newDetails);
|
||||
public function pluck();
|
||||
|
||||
}
|
56
Modules/Employee/app/Repositories/EmployeeRepository.php
Normal file
56
Modules/Employee/app/Repositories/EmployeeRepository.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Employee\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Employee\Models\Employee;
|
||||
|
||||
class EmployeeRepository implements EmployeeInterface
|
||||
{
|
||||
public function findAll()
|
||||
{
|
||||
return Employee::when(true, function ($query) {
|
||||
if (auth()->user()->hasRole('employee')) {
|
||||
$user = \Auth::user();
|
||||
$query->where('id', $user->employee_id);
|
||||
}
|
||||
})->paginate(20);
|
||||
}
|
||||
|
||||
public function getEmployeeById($employeeId)
|
||||
{
|
||||
return Employee::findOrFail($employeeId);
|
||||
}
|
||||
|
||||
public function getUserByEmpId($employeeId)
|
||||
{
|
||||
$employee = Employee::findOrFail($employeeId);
|
||||
return $employee->user ?? null;
|
||||
}
|
||||
|
||||
public function getEmployeeByEmail($email)
|
||||
{
|
||||
return Employee::where('email', $email)->first();
|
||||
}
|
||||
|
||||
public function delete($employeeId)
|
||||
{
|
||||
Employee::destroy($employeeId);
|
||||
}
|
||||
|
||||
public function create($employeeDetails)
|
||||
{
|
||||
return Employee::create($employeeDetails);
|
||||
}
|
||||
|
||||
public function update($employeeId, array $newDetails)
|
||||
{
|
||||
return Employee::whereId($employeeId)->update($newDetails);
|
||||
}
|
||||
|
||||
public function pluck()
|
||||
{
|
||||
return Employee::pluck(DB::raw('CONCAT(first_name, " ", COALESCE(middle_name, " "), " ", last_name) AS full_name'), 'id');
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user