2

This is my route, having 2 parameters,

url: '{{ route('datatable.getaccess', [$room->id_project , $room->id]) }},

if write like that will shown : xxxxxx?xxxxxx , that have question mark beetwen id_project to $id , how to write correctly? because that should "/" slash

Thank you.

6
  • What does that route look like in your web.php routes file? Commented Dec 5, 2019 at 14:34
  • I guess its perfect. your route is having one route parameter and other value is appended as query parameter Commented Dec 5, 2019 at 14:34
  • @kerbholz Route::get('viewroom/{id_project}/{id}', 'RoomController@show'); like that Commented Dec 5, 2019 at 14:38
  • @PrashantDeshmukh..... sorry i don't get your answer, whats that mean ? my route have 2 paramters , Commented Dec 5, 2019 at 14:39
  • Where is route name ? It should be like this Route::get('viewroom/{id_project}/{id}', 'RoomController@show')->name('datatable.getaccess'); Commented Dec 5, 2019 at 14:39

1 Answer 1

3

You can use string placeholders for javascript.

<input type="hidden" id="_room_id" value="{{ $room->id }}">
<input type="hidden" id="_room_project_id" value="{{ $room->id_project }}">
let project_id = $('#_room_project_id').val(); // or document.getElementById('_room_project_id').value if you're not using JQuery
let id = $('#_room_id').val();                 // or document.getElementById('_room_id').value if you're not using JQuery
let url = "{{ route('datatable.getaccess', [':project_id', ':id']) }}".replace(':project_id', project_id).replace(':id', id);

This looks wrong but it works since we're passing strings to the route helper (which in turn produces a string)

route('datatable.getaccess', [':project_id', ':id'])
// 'viewroom/:project_id/:id'

so

let url = "{{ route('datatable.getaccess', [':project_id', ':id']) }}".replace(':project_id', project_id).replace(':id', id);

is equivalent to

let url = "viewroom/:project_id/:id".replace(':project_id', project_id).replace(':id', id);
Sign up to request clarification or add additional context in comments.

1 Comment

this has realy helped a bunch for me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.