Book a Table

Learn the importance of having dedicated routes for each different kind of action.

New API endpoint

We will add a new route under the restaurant_required route group. You may have noticed that we are keeping our routes specific and dedicated to a single action. This practice is beneficial when designing large or complex web applications. Rather than trying to keep the number of routes to a minimum, you should try to keep them as specific as possible to avoid any confusion.

<?php
// ...
        Route::prefix('orders')->group(function () {
            Route::post('/book-a-table/{tableId}', [OrderController::class, 'bookATable']);
        });
// ...

Execution

We already added a helper method in the Table Eloquent model to change the state. Other than that, all we need to do is to create a new order and return its id so that the user can use it to add order items and complete the order in the future.

Get hands-on with 1200+ tech skills courses.