我正在尝试检索已分配给它们的轨道的类型列表,我正在使用whereHas雄辩的查询但感觉有点迷失.
我有以下内容
//model
public function workingGenre() {
$this->whereHas('tracks', function($query) {
$query->where('');
});
return $this->tracks()->first();
}
//controller (where i am passing variables etc)
$genres = Genre::with('tracks')->get();
//my view
@foreach($genres as $genre)
{{print_r($genre->workingGenre())}}
@endforeach
Run Code Online (Sandbox Code Playgroud)
我知道我的Where是空的,目前我的print_r返回以下内容:
1
App\Track Object
(
[table:protected] => Track
[fillable:protected] => Array
(
[0] => id
[1] => GenreId
[2] => Title
[3] => CreatedById
[4] => SelectedCount
[5] => ProducerName
[6] => SourceId
[7] => Published
)
[connection:protected] =>
[primaryKey:protected] => id
[perPage:protected] => 15
[incrementing] => 1 …Run Code Online (Sandbox Code Playgroud) 我试图通过距离参数(以英里为单位)将用户位置(通过URL中的params发送)与offers.offer_lat和offers.offer_long(在我的数据库中)进行比较
我现在发疯了,我在网上找到的很多解决方案很难通过DB :: raw移植到laravels查询构建器,我目前在查询范围内有函数,因为用户将使用过滤API结果距离,但没有运气!
我在网上发现了一些用于计算hasrsine的函数,但我不知道如何使用它们.这是一个例子:https: //gist.github.com/fhferreira/9081607
任何帮助都将受到大力赞赏!:)
谢谢