Skip to content

Instantly share code, notes, and snippets.

@marifuli
Last active March 31, 2022 20:04
Show Gist options
  • Save marifuli/b88ee23a117e5aaf8a589b42f40df4dc to your computer and use it in GitHub Desktop.
Save marifuli/b88ee23a117e5aaf8a589b42f40df4dc to your computer and use it in GitHub Desktop.
Route::any('/dynamic/route/{class}/{method}', function ($class, $method) {
$class = "\App\Http\Controllers\\" . str_replace('-', "/", $class);
// return $class;
$con = new $class();
return $con->$method();
})->name('dynamic.route');
global.route2 = (classAndMethodName, params = {}) => {
let array = classAndMethodName.split('@')
params.class = array[0].replace(/\\/g, '-')
params.method = array[1]
return route('dynamic.route', params)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment