I use Laravel 5.4 and now I want to make dynamic route to controller which mean I can access UserController and Profile function throw route directly, for example.
GET http://localhost/user/profile?userid=123
The example URL above will access UserController and function profile with dynamic parameters after ?. And if I want to access different controller, I just need to change user param to Controller name.
I created a route like this and it works.
Route::get('v1/{controller_name}/{function_name}/{query?}', function ($controller_name, $function_name){
$app = app();
$controller = $app->make('\App\Http\Controllers\Api\\'.$controller_name.'Controller');
return $controller->callAction($function_name, $parameters = array());
});
But I don't know how to pass parameters.
Any other better way to do this?