How can put the data into an array in laravel blade javascript? #21453
-
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Hi @comprog-ux, I actually have a side-project at https://ezmap.co (open sourcing the code on this is on my radar) that does exactly this stuff. Built on Laravel and outputting stuff like this in JS. Laravel escapes certain output by default for safe rendering but in this case you want the actual code to be output. Try this:
reference: Blade Templates - Laravel - The PHP Framework For Web Artisans Depending on how Let me know how you get on or if you need anything more. Cheers, |
Beta Was this translation helpful? Give feedback.
-
also this bit looks like the lines are the wrong way round, set the variable then access it in the loop
comprog-ux:
|
Beta Was this translation helpful? Give feedback.
-
I found out the way to do it. |
Beta Was this translation helpful? Give feedback.
I found out the way to do it.
var locations = [
@foreach ($data as $i)
[ "{{ $i->name }} " + “i " + “{{ $i->contact_city }}” + " br>” + “{{ $i->date }}” + " Anmälda: " + “{{ $i->signups_count }}” , {{ $i->lat }},{{ $i->lng }},0, “{{ $i->signups_closing_date }}” , “{{ $i->closed_at }}”,‘http://localhost:8080/app/competitions/’+{{ $i->id }}+ ‘/information’],
@Endforeach
];
And for the loop where I put out the markers:
var t=new Date();
var visa;
var ldstr=t.toLocaleDateString(); // Today’s date.
// The loop
for (i = 0; i < locations.length; i++) {
date1=new Date(locations[i][4]);
date2=new Date(ldstr);
var newLat = locations[i][1] + (Math.random() -.5) / 20;// * (Math.random() * (max - min)…