First of all, we rename the Example folder in Requests to Lodgings. In Lodgings, we also suddenly rename the request that we are going to use to GetLodgingsRequest.php.
In the request file we are going to build the entire request. Think of it a bit like building the body.
In our construct we pass in the necessary values that we passed in the collection:
/**
* Define constructor.
*
* @param string|null $city City you'd like to request lodgings from, leaving it empty will return all lodgings from Flanders.
* @param int $limit Amount per page in pagination. -1 is the default (unlimited).
* @param int $page current page in pagination. -1 is the default (disable pagination).
*/
public function __construct(protected ?string $city, protected int $limit, protected int $page)
{
$this->city = $city;
$this->limit = $limit;
$this->page = $page;
}
We define our endpoint:
/sector/accommodation/base_registry.json
We also add our query parameters:
public function defaultQuery(): array
{
return [
'city' => $this->city,
'limit' => $this->limit,
'page' => $this->page
];
}
and then we are done with the request!
Now we have a basic collection in which we can call a request in our Laravel/PHP application.