Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
wapmorgan committed Mar 5, 2023
1 parent 14d1c39 commit 55358e8
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ written in PHP from source code directly. You **do not need** to write OpenApi-s
## Laravel Example

1. Routes:

```php
Route::get('/selector/lists', [\App\Http\Controllers\SelectorController::class, 'lists']);
Route::post('/selector/select', [\App\Http\Controllers\SelectorController::class, 'select']);
Expand All @@ -36,38 +37,40 @@ written in PHP from source code directly. You **do not need** to write OpenApi-s
```

2. One controller:

```php
/**
* Returns lists of filters
* @param Request $request
* @return ListsResponse
*/
public function lists(Request $request) {
return new ListsResponse([
// 'persons' => range(1, 15),
'persons' => array_keys(Menu::$personsList),
'tastes' => Menu::$tastes,
'meat' => Menu::$meat,
'pizzas' => Menu::$pizzas,
]);
}

/**
* Makes a selection of pizzas according to criteria
* @param \App\Http\Requests\SelectPizzas $request
* @return PizzaListItem[]
*/
public function select(\App\Http\Requests\SelectPizzas $request) {
$validated = $request->validated();

return (new Selector())->select(
$validated['city'], $validated['persons'],
$validated['tastes'] ?? null, $validated['meat'] ?? null,
$validated['vegetarian'] ?? false, $validated['maxPrice'] ?? null);
}
* Returns lists of filters
* @param Request $request
* @return ListsResponse
*/
public function lists(Request $request) {
return new ListsResponse([
// 'persons' => range(1, 15),
'persons' => array_keys(Menu::$personsList),
'tastes' => Menu::$tastes,
'meat' => Menu::$meat,
'pizzas' => Menu::$pizzas,
]);
}
/**
* Makes a selection of pizzas according to criteria
* @param \App\Http\Requests\SelectPizzas $request
* @return PizzaListItem[]
*/
public function select(\App\Http\Requests\SelectPizzas $request) {
$validated = $request->validated();
return (new Selector())->select(
$validated['city'], $validated['persons'],
$validated['tastes'] ?? null, $validated['meat'] ?? null,
$validated['vegetarian'] ?? false, $validated['maxPrice'] ?? null);
}
```

3. One request and two responses:

```php
class SelectPizzas extends FormRequest {
public function rules()
Expand Down

0 comments on commit 55358e8

Please sign in to comment.