Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

270
Views
how can i set route name in javascript code in laravel

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);

}

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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');
about 4 years ago · Juan Pablo Isaza Report

0

You can try like this inside your javascript function:

var uri = "{{ route('routeName', ':variable') }}";
uri = uri.replace(':variable', yourvariable);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!