Created
March 27, 2022 23:19
-
-
Save marifuli/8db1340c82ada4a094a1f24ca98693bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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