StocksNew/Modules/Leave/app/Repositories/LeaveRepository.php
Sampanna Rimal 53c0140f58 first commit
2024-08-27 17:48:06 +05:45

53 lines
1.4 KiB
PHP

<?php
namespace Modules\Leave\Repositories;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Modules\Leave\Models\Leave;
class LeaveRepository implements LeaveInterface
{
public function findAll($filters = [], $limit = null, $offset = null)
{
return Leave::with(['leaveType', 'employee'])->when($filters, function ($query) use ($filters) {
if (isset($filters["employee_id"])) {
$query->whereHas('employee', function (Builder $query) use ($filters) {
$query->where('id', '=', $filters["employee_id"]);
});
}
if (isset($filters["status"])) {
$query->where("status", $filters["status"]);
}
if (isset($filters["date"])) {
$explodeDate = explode("to", $filters['date']);
$query->whereBetween("start_date", [$explodeDate[0], preg_replace('/\s+/', '', $explodeDate[1])]);
}
})->get();
}
public function getLeaveById($leaveId)
{
return Leave::findOrFail($leaveId);
}
public function delete($leaveId)
{
Leave::destroy($leaveId);
}
public function create(array $leaveDetails)
{
return Leave::create($leaveDetails);
}
public function update($leaveId, array $newDetails)
{
return Leave::where('leave_id', $leaveId)->update($newDetails);
}
}