Skip to content

Instantly share code, notes, and snippets.

@marifuli
Created March 27, 2022 23:19
Show Gist options
  • Save marifuli/8db1340c82ada4a094a1f24ca98693bf to your computer and use it in GitHub Desktop.
Save marifuli/8db1340c82ada4a094a1f24ca98693bf to your computer and use it in GitHub Desktop.
// Route
Route::any('/dynamic/route/{class}/{method}', function ($class, $method) {
$class = "\App\Http\Controllers\\" . str_replace('-', "/", $class);
$con = new $class();
return $con->$method();
})->name('dynamic.route');
// JS
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