user4370900
user4370900

Reputation:

Laravel automatize routes

I am using some routes in my laravel App like this:

Route::get('/structure', 'Superuser\StructureController@index'); 

So if I go to localhost/myproject/structure I am using StructureController and it's method "index". Now I would like to use another features, like add, update, delete, reorder etc... Is there any simple way, that I needn't to write:

Route::get('/structure/add', 'Superuser\StructureController@add');
Route::get('/structure/update/{url}', 'Superuser\StructureController@update');
Route::get('/structure/delete/{url}', 'Superuser\StructureController@delete');

If is this possible, I would like to use ::get for everything. Thank you a lot.

Upvotes: 1

Views: 37

Answers (1)

Andrew
Andrew

Reputation: 20071

If you want to use GET for everything i dont think there is a built in automated way to do it, though you could write a method that spits out routes based on a passed in controller name perhaps.

There is automated RESTful/Resourceful routes for resource controllers:

Route::resource('photos', 'PhotoController');

This would generate these routes:

Actions Handled By Resource Controller
Verb    URI                    Action   Route Name
GET     /photos                index    photos.index
GET     /photos/create         create   photos.create
POST    /photos                store    photos.store
GET     /photos/{photo}        show     photos.show
GET     /photos/{photo}/edit   edit     photos.edit
PUT/PATCH   /photos/{photo}    update   photos.update
DELETE  /photos/{photo}        destroy  photos.destroy

https://laravel.com/docs/5.5/controllers#resource-controllers

Upvotes: 1

Related Questions