Skip to content

[7.x] Add apiResource in RouteRegistrar - #31857

Merged
taylorotwell merged 2 commits into
laravel:7.xfrom
LasseRafn:patch-1
Mar 9, 2020
Merged

[7.x] Add apiResource in RouteRegistrar#31857
taylorotwell merged 2 commits into
laravel:7.xfrom
LasseRafn:patch-1

Conversation

@LasseRafn

@LasseRafn LasseRafn commented Mar 9, 2020

Copy link
Copy Markdown
Contributor

Since Laravel 7.X has a new (optimized) routing implemented, route names are more important, and caching routes will break if naming collisions happen.

Normally you can use Route::name('posts')->resource(..... to change the name of a group (useful for nested routes like: /posts/{post}/comments)

HOWEVER, this is not possible with apiResource.

I propose this change to allow that. Its just a convenience to replace:

Route::name('posts')->resource('posts/{post}/comments', 'PostCommentsController')->only(['index', 'show', 'store', 'update', 'destroy']);

With:

Route::name('posts')->apiResource('posts/{post}/comments', 'PostCommentsController');

@GrahamCampbell GrahamCampbell changed the title Add apiResource in RouteRegistrar [7.x] Add apiResource in RouteRegistrar Mar 9, 2020
@taylorotwell
taylorotwell merged commit a2ca152 into laravel:7.x Mar 9, 2020
@LasseRafn
LasseRafn deleted the patch-1 branch January 28, 2021 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants