File: D:/HostingSpaces/SBogers10/farmfun.komma.pro/app/Komma/Availability/Queries/SearchAmountQuery.php
<?php
namespace App\Komma\Availability\Queries;
use App\Komma\Availability\AvailabilityService;
use App\Komma\SearchAmountOfPersons\SearchAmountOfPersonsService;
final class SearchAmountQuery extends AbstractAvailabilityProductFilterQuery
{
/** @var SearchAmountOfPersonsService */
private $searchAmountOfPersonsService;
public function __construct()
{
$this->searchAmountOfPersonsService = app(SearchAmountOfPersonsService::class);
}
/**
* Check if we should run the filter
*
* @return bool
*/
public function shouldRunFilter(): bool
{
return session()->get(AvailabilityService::SEARCH_AMOUNT_KEY, null) !== null;
}
public function filter($query)
{
$searchAmountOption = $this->searchAmountOfPersonsService->getOptionById(session()->get(AvailabilityService::SEARCH_AMOUNT_KEY));
return $query->where('products.minimum_amount_of_persons', '<=', $searchAmountOption->maximum)
->where(function ($subQuery) use ($searchAmountOption) {
$subQuery->where('products.maximum_amount_of_persons', '>=', $searchAmountOption->minimum)
->orWhere('products.maximum_amount_of_persons', '=', 0);
});
}
}