Files
fuel-price/app/Http/Requests/Api/NearbyStationsRequest.php
Ovidiu U 7101ed3550
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.3) (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled
feat: add postcode resolution to /api/stations and Filament SearchResource
Extends NearbyStationsRequest to accept `postcode` (full or outcode) as an alternative to lat/lng. PostcodeService resolves it via postcodes.io and falls through to coordinates. Also adds SearchResource to the Filament admin panel for viewing logged search activity with fuel type filter and price/distance stats columns. Includes SQLite GREATEST/LEAST function polyfills in AppServiceProvider for test compatibility.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 19:10:25 +01:00

43 lines
1.1 KiB
PHP

<?php
namespace App\Http\Requests\Api;
use App\Enums\FuelType;
use Illuminate\Foundation\Http\FormRequest;
class NearbyStationsRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'postcode' => ['nullable', 'string', 'max:10'],
'lat' => ['required_without:postcode', 'nullable', 'numeric', 'between:-90,90'],
'lng' => ['required_without:postcode', 'nullable', 'numeric', 'between:-180,180'],
'fuel_type' => ['required', 'string'],
'radius' => ['nullable', 'numeric', 'between:0.1,50'],
'sort' => ['nullable', 'string', 'in:price,distance'],
'pricing_mode' => ['nullable', 'string', 'in:pump'],
];
}
public function fuelType(): FuelType
{
return FuelType::fromAlias($this->string('fuel_type')->toString());
}
public function radius(): float
{
return (float) $this->input('radius', 10.0);
}
public function sort(): string
{
return $this->input('sort', 'price');
}
}