first change

This commit is contained in:
2025-07-27 17:40:56 +05:45
commit f8b9a6725b
3152 changed files with 229528 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
<?php
namespace Modules\Employee\Repositories;
use Illuminate\Http\Request;
use Modules\Employee\Interfaces\EmployeeInterface;
use Modules\Employee\Models\Employee;
class EmployeeRepository implements EmployeeInterface
{
public function findAll($request, callable $query = null, bool $paginate = false, int $limit = 10)
{
$baseQuery = Employee::query();
if ($request->filled('search')) {
$baseQuery->whereAny(
[
'first_name',
'middle_name',
'last_name',
],
'LIKE',
"%{$request->search}%"
);
}
if ($request->filled('email')) {
$baseQuery->where('email', 'LIKE', "%{$$request->email}%");
}
if ($query) {
$query($baseQuery);
}
if ($paginate) {
return $baseQuery->paginate($limit);
}
return $baseQuery->get();
}
public function findById($id, callable $query = null)
{
$baseQuery = Employee::query();
if (is_callable($query)) {
$query($baseQuery);
}
return $baseQuery->where('id', $id)->firstOrFail();
}
public function delete($id)
{
$employee = $this->findById($id);
$employee->delete();
return $employee;
}
public function create(array $data)
{
$employee = Employee::create($data);
return $employee;
}
public function update($id, array $data)
{
$employee = $this->findById($id);
$employee->update($data);
return $employee;
}
public function pluck(callable $query = null)
{
$baseQuery = Employee::query();
if (is_callable($query)) {
$query($baseQuery);
}
return $baseQuery->get()->mapWithKeys(function ($employee) {
return [$employee->id => $employee->full_name];
});
}
public function terminate($id){
$employee = $this->findById($id);
$employee->update(["status" => "terminated"]);
return $employee;
}
}