44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\CostCalculator\Services;
|
|
|
|
use Modules\CostCalculator\Models\CostCalculator;
|
|
|
|
class CostCalculatorService
|
|
{
|
|
public function findAll($request)
|
|
{
|
|
return CostCalculator::when($request, function ($query) use ($request) {
|
|
if ($request->filled('country_id')) {
|
|
$query->where('country_id', $request->country_id);
|
|
}
|
|
|
|
if ($request->filled('programlevel_id')) {
|
|
$query->where("programlevel_id", $request->programlevel_id);
|
|
}
|
|
|
|
if ($request->filled('program_id')) {
|
|
$query->where("program_id", $request->program_id);
|
|
}
|
|
|
|
if ($request->filled('living_status_id')) {
|
|
$query->where("living_status_id", $request->living_status_id);
|
|
}
|
|
|
|
if ($request->filled('status')) {
|
|
$query->where('status', $request->status);
|
|
}
|
|
|
|
})->latest()->paginate(10)->withQueryString();
|
|
}
|
|
|
|
public function pluck(callable $query = null)
|
|
{
|
|
$baseQuery = CostCalculator::query();
|
|
if (is_callable($query)) {
|
|
$query($baseQuery);
|
|
}
|
|
return $baseQuery->pluck('title', 'id');
|
|
}
|
|
}
|