laravel routing like code igniter laravel routing like code igniter codeigniter codeigniter

laravel routing like code igniter


Is there a way to have an auto routing like CI

Why yes there is. In your route file do Route::controller(Controller::detect());

Now in your controller class make sure each function name is concatenated with action_. So if your function name is homepage() then make it action_homepage()

Keep in mind that you can use restful controller names get_homepage() and post_homepage(). But you'll have to declare this class variable in your controller public static $restful = true;


    //create controller name like UserController//Steps:// 1. route matched to either post or get request, // 2. used web/controllerName/MethodName/Parameter1/parameter2 .. // all parameters received in an array as $params. web/ is used like a route // prefix. If no method is passed it will call index method// 3. explode the parameter// 4. called the controller with method and paramteres passed// 5. parameters are matched for regex allowing alphanumeric and slash (url)// 6. passed through guest middleware// created controller as mentioned below:// class SomeController extends Controller// {//     public function index($param1,$param2,$param3){//       return 'index'.$param1.$param2.$param3;//     }// }Route::match(['get','post'],'/web/{controller}/{method?}/{params?}', function ($controller, $method='index', $params='') {        $params = explode('/', $params);    $controller = app()->make("\App\Http\Controllers\\". ucwords($controller).'Controller' );    return $controller->callAction($method, $params);})->where('params', '[A-Za-z0-9/]+')->middleware('guest');