In my Laravel 5.3 project I have this in my controller to achieve competitions table data:
public function list(){
$data=Competition::all();
return view('map', ['data'=> $data]);
}
The route:
Route::get('map', 'Api\CompetitionsController@list');
With these lines of code i my map.blade.php (in the html area) for five columns (two posts):
<ul>
@foreach ($data As $i)
{{ $i->id }} {{ $i->name }} {{ $i->contact_city }} {{ $i->lat }} {{ $i->lng }}
@endforeach
</ul>
I got printouts for five columns (two posts) like this:
1 Fälttävlan Landskrona 55.87 12.83 2 Fälttävlan Sundsvall 62.39 17.31
In my script area for the map I want to make an array containing these example five data for each post in the database table to create markers on the map. How do I do that? The $data contains everything in the DB table as not only data but column names and so on.
I solved the problem. This code made it:
var locations = [
@foreach ($data as $i)
[ "{{ $i->name }} " + "{{ $i->contact_city }}" , {{ $i->lat }},{{ $i->lng }},0, 'https://test.webshooter.se/app/competitions/'+{{ $i->id }}+ '/information'],
@endforeach
];
The code is in the map script.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.