57 lines
1.5 KiB
PHP
57 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Modules\PMS\Repositories;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Modules\PMS\Models\Task;
|
|
|
|
class TaskRepository implements TaskInterface
|
|
{
|
|
public function findAll($filters = [], $limit = null, $offset = null)
|
|
{
|
|
return Task::when($filters, function ($query) use ($filters) {
|
|
if (isset($filters["search"])) {
|
|
$search = $filters['search'];
|
|
$query->whereAny(['title'], 'LIKE', "%$search%");
|
|
}
|
|
|
|
if (isset($filters["status"])) {
|
|
$query->where("status", $filters["status"]);
|
|
}
|
|
|
|
if (isset($filters["date"])) {
|
|
$explodeDate = explode("to", $filters['date']);
|
|
// dd($filters['date'], preg_replace('/\s+/', '', $explodeDate[1]));
|
|
$query->whereBetween("start_date", [$explodeDate[0], preg_replace('/\s+/', '', $explodeDate[1])]);
|
|
}
|
|
|
|
})->get();
|
|
}
|
|
|
|
public function getTaskById($TaskId)
|
|
{
|
|
return Task::findOrFail($TaskId);
|
|
}
|
|
|
|
public function delete($TaskId)
|
|
{
|
|
Task::destroy($TaskId);
|
|
}
|
|
|
|
public function create($TaskDetails)
|
|
{
|
|
return Task::create($TaskDetails);
|
|
}
|
|
|
|
public function update($TaskId, array $newDetails)
|
|
{
|
|
return Task::whereId($TaskId)->update($newDetails);
|
|
}
|
|
|
|
public function pluck()
|
|
{
|
|
return Task::pluck(DB::raw('CONCAT(first_name," ", middle_name , " ",last_name) AS full_name'), 'id');
|
|
}
|
|
|
|
}
|