0

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:

<?php

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

Where CustomController is the controller which will run the request to the view Action

With ASP.NET Core, it is something like:

routes.MapRoute(
    name: "default",
    template: "{controller=Home}/{action=Index}");
});
Victor Castro
  • 1,232
  • 21
  • 40

1 Answers1

1

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.

craig_h
  • 31,871
  • 6
  • 59
  • 68
  • yes but... no. The goal is to have 1 route for X controllers where the controller is choosen IN THE URL and can be used as a variable is the routing module. – Victor Castro Oct 24 '16 at 09:14
  • 1
    As far as I'm aware that isn't something that is built into `laravel`, if you need that functionality you will need to extend the router. – craig_h Oct 24 '16 at 09:25