List Orders of a Restaurant

Learn about one more exciting feature of Laravel: Query Scopes.

New URLs

We should let the user fetch the list of open orders and the list of completed orders of a restaurant.

// ...
    Route::prefix('orders')->group(function () {
        Route::get('/list-open', [OrderController::class, 'listOpen']);
        Route::get('/list-completed', [OrderController::class, 'listCompleted']);
        // ...
// ...

Query scopes

Time to learn one more Laravel feature while building new API endpoints.

The Eloquent query builder allows you to add query scopes to model classes, which makes your code more readable and reusable. Notice the highlighted lines in the following code.

Get hands-on with 1200+ tech skills courses.