我试图让使用该商店定位器应用程序的教程和Laravel 5.在这些问题的人在这里,并在这里似乎可以用@foreach循环和其他刀片的模板语言通过自己的经/纬度坐标运行.他们是怎么做到的?
当我的地图代码在js文件中时,我基本上不知道如何使用刀片循环坐标?怎么可能?我做错了吗?
我正在使用具有以下代码的js文件(maps.js)显示我的地图:
function initialize() {
var map_canvas = document.getElementById('map');
// Initialise the map
var map_options = {
center: location,
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(map_canvas, map_options)
// Put all locations into array
var locations = [
@foreach ($articles as $article)
[ {{ $article->lat }}, {{ $article->lng }} ]
@endforeach
];
for (i = 0; i < locations.length; i++) {
var location = new google.maps.LatLng(locations[i][0], locations[i][1]);
var marker = …
Run Code Online (Sandbox Code Playgroud) 理想情况下,我正在寻找一个Laravel 5相关答案.我正在尝试制作商店定位器应用程序.我正在尝试将一对纬度/经度坐标(根据用户进入搜索框的地址计算)与我的数据库中最近的(在半径100km范围内)坐标/现有商店相匹配.
用户输入一个地址(使用地理编码)转换为lat和lng坐标.这些内容会发送到我的"文章"页面,其中包含商店列表和谷歌地图.我使用了一个关于范围搜索的简单教程,根据文本"地址"显示我的文章/商店.但这显然不适用于两个坐标.我有一个名为文章的表,其中包括:id,地址,lat,lng,网站,标题等.
当前文章模型:
public function scopeSearch($query, $search){
return $query->where('address', 'LIKE', "%$search%" );
}
Run Code Online (Sandbox Code Playgroud)
文章控制器
public function index(Request $request)
{
$query = $request->get('q');
$articles = $query
? Article::search($query)->get()
: Article::all();
return view('articles.index', compact('categories'))->withArticles($articles);
}
Run Code Online (Sandbox Code Playgroud)
当前表单/地理编码:
{!! Form::open(['method' => 'GET', 'id' => 'searchForm', 'name' => 'searchForm', 'route' => 'articles_path']) !!}
{!! Form::input('search', 'q', null, ['placeholder' => 'LOCATION', 'class' => 'locationSearch', 'id' => 'searchInput'])!!}
{!! Form::hidden('lat', null, ['id' => 'lat'])!!}
{!! Form::hidden('lng', null, ['id' => 'lng'])!!}
{!! …
Run Code Online (Sandbox Code Playgroud) 这与这个问题非常相似.我正在使用Laravel 5并尝试使用表单将文件(图像)添加到我的数据库中.我有一个表单,可以在我的文章类中添加各种数据(标题,描述,图像).一篇文章还有'belongsToMany'类别和天数(很多到很多r/ship).下面的代码允许我上传我的数据,但它添加了文章的三个实例!前两个实例具有正确的照片路径/名称(photo.jpg).第三个实例将这样的名称添加到db:/ tmp/phphJIIY1.它正确地为数据透视表添加了ID.
我认为这就是'商店'功能的这一行
$article = Article::create($request->all());
Run Code Online (Sandbox Code Playgroud)
这导致了问题,但我需要那条线,否则我会得到上一个问题中描述的错误.
如何订购/更改此代码,以便我可以上传图片并在文章中添加类别/天数?我已经安装了干预\图像但尚未使用它.
public function create()
{
$categories = Category::lists('name', 'id');
$days = Day::lists('dayname', 'id');
return view('articles.create', compact('categories', 'days'));
}
public function store(ArticleRequest $request)
{
$image_name = $request->file('image')->getClientOriginalName();
$request->file('image')->move(base_path().'/public/images', $image_name);
$article = ($request->except(['image']));
$article['image'] = $image_name;
Article::create($article);
Run Code Online (Sandbox Code Playgroud)
//上面这条线路本身很好用(如果我在这里评论它可以正常工作,但我需要我的很多很多人去工作)
$article = Article::create($request->all());
Run Code Online (Sandbox Code Playgroud)
//必须添加以上行才能使'categories()'工作.
$categoriesId = $request->input('categoryList');
$article->categories()->attach($categoriesId);
$daysId = $request->input('dayList');
$article->days()->attach($daysId);
return redirect()->route('articles_path');
}
Run Code Online (Sandbox Code Playgroud)