LeCintas LeCintas - 1 year ago 71
PHP Question

Wildcard to route to a controller

I am absolutely novice with Laravel and I am currently learning the routes feature of the Framework.

I want to know if it is possible to do like we can do with ASP.NET that is to redirect to a Controller written in the URL.

Actually, to do something like:


Route::get('/{CustomController}/{Action}', function ($controller, $action) {
return controller($controller, $action);

is the controller which will run the request to the view

With ASP.NET Core, it is something like:

name: "default",
template: "{controller=Home}/{action=Index}");

Answer Source

Yes, with routes in laravel the format is this:

Route::get('/custom-controller', 'CustomController@index');

If you are using the standard method names in your controller such as index(), store() etc

you can use resource instead and it will automatically build up all your routes:

Route::resource('/my-route', 'CustomController');

If you then do php artisan route:list you will see laravel has automatically added all the standard routes for your controller.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download