57 lines
1.3 KiB
PHP
57 lines
1.3 KiB
PHP
|
<?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');
|
||
|
}
|
||
|
|
||
|
}
|