Skip to main content
Tutorial Free

Resource Controllers for API: How to Remove create/edit methods?

July 24, 2017
1 min read
Resource controllers are great for CRUDs, but if we use them for APIs, there are two unnecessary methods - create() and edit(), cause there are no visual forms for it. So how to remove them from routes? There are two ways. First: did you know that you can add another parameter to Route::resource()? Like this:
Route::resource('roles', 'RolesController', ['except' => ['edit', 'create']]);
So, just list the methods you won't use. Or, alternatively, list methods you only want to use:
Route::resource('roles', 'RolesController', [
  'only' => ['index', 'show', 'store', 'update', 'destroy']
]);

Second: From Laravel 5.4.24 we have a new route function apiResource()
Route::apiResource('roles', 'RolesController');
It will form and pass the same only parameter as in example above. Thanks Lasse Rafn for pointing it out on Twitter.

Enjoyed This Tutorial?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Recent Courses on Laravel Daily

Next.js Basics for Laravel Developers

11 lessons
58 min

Roles and Permissions in Laravel 13

14 lessons
57 min

Testing in Laravel 13 For Beginners

26 lessons
1 h 41 min read

No comments yet…