I'm using Ajax to get and display content in a Laravel view. I'd like to know how I can access the second parameter in the URL. It's currently giving me back a random string:
for(var i=0;i<array.length;i++){
html+="<a href={{ route('showAnnouncement',"array[i].id_announcement") }}>";
}
When I alert array{i].id_announcement
I get its value, but it doesn't pass in the URL.
Thank you!
You can't access a JS value inside a php code.
{{route('showAnnouncement',"array[i].id_announcement") }}
This not possible, If you are making ajax request you try something like this below.
var an_id = array[i].id_announcement;
$.ajax({
url: '{{route('showAnnouncement')}}',
data: {'an_id':an_id },
type: 'POST',
success: function (result)
{
}
});
Route
Route::post('showAnnouncement/{an_id?}', ['as' => 'showAnnouncement', 'uses' => 'YourController@showAnnouncement']);
Guys finally I found a solution and it worked like a charm
for(var i=0;i<array.length;i++){
var url = '{{ route("showAnnouncement", ":id") }}';
url = url.replace(':id', array[i].id_announcement);
html+="<a href='"+url+"'>";