Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create resource route in Laravel without certain methods

I'm building my web application with some AJAX and I'm not using all the methods from a resource controller. Is it possible to create a resource controller without some methods with php artisan? Thanks

like image 721
Elias Garcia Avatar asked Feb 07 '23 08:02

Elias Garcia


1 Answers

You may specify which routes you would like to be included for the resource by passing an argument to the route definition like so:

Route::resource('photo', 'PhotoController', ['only' => [
    'index', 'show'
]]);

When you run the artisan generator you will still get all the methods, but you can just delete them. If you were to create a custom command to only create certain methods, you would still need to keep in mind that Route::resource expects all resource routes by default.

like image 145
tam5 Avatar answered Feb 26 '23 02:02

tam5