I want to assign/set route in javascript code. I have javascript method which take route name in parameter and I want to assign that parameter in route as below.
function assign_route(route_name){
var url = "{{ route(' route_name ') }}";
OR As below
var url = "{{ route('old_url') }}"; url = url.replace('old_url', route_name);
}
CodePudding user response:
You can try like this inside your javascript function:
var uri = "{{ route('routeName', ':variable') }}";
uri = uri.replace(':variable', yourvariable);
CodePudding user response:
You can specify named routes by chaining the name method onto the route definition:
Route::get('user/profile', function () { // })->name('profile');
You can specify route names for controller actions:
Route::get('user/profile', 'UserController@showProfile')->name('profile');