Laravel - Controllers - Restful Scoping Resource Routes

Laravel's scoped implicit model binding feature can automatically scope nested bindings such that the resolved child model is confirmed to belong to the parent model. By using the scoped method when defining your nested resource, you may enable automatic scoping as well as instruct Laravel which field the child resource should be retrieved by:

    use App\Http\Controllers\PhotoCommentController;
    Route::resource('photos.comments', PhotoCommentController::class)->scoped([
        'comment' => 'slug',

This route will register a scoped nested resource that may be accessed with URIs like the following:


When using a custom keyed implicit binding as a nested route parameter, Laravel will automatically scope the query to retrieve the nested model by its parent using conventions to guess the relationship name on the parent. In this case, it will be assumed that the Photo model has a relationship named comments (the plural of the route parameter name) which can be used to retrieve the Comment model.