Laravel Algolia侦察兵,关系方面的人

问题描述

我正在研究Laravel项目。我正在使用基于Algolia的Scout。但是我努力地在关系中使用whereIn。我有2种型号,如下。

Place.php

class Place extends Model
{
    use Searchable,Localizable;

    protected $with = [
        'images','phones','emails','categories'
    ];

    protected $casts = [
        'is_featured' => 'boolean'
    ];

    public function categories()
    {
        return $this->belongsToMany(Category::class,'place_category');
    }

    public function searchableAs()
    {
        return "places_index";
    }

    public function toSearchableArray()
    {
        $record = $this->toArray();
        $record['_geoloc'] = [
            'lat' => $record['latitude'],'lng' => $record['longitude'],];
        $record['categories'] = $this->categories->map(function ($data) {
            return [
                'id' => $data['id'],'en_name' => $data['en_name'],'mm_name' => $data['mm_name'],];
        })->toArray();
        unset($record['created_at'],$record['updated_at'],$record['latitude'],$record['longitude']);
        unset($record['images'],$record['phones'],$record['emails']);

        return $record;
    }
}

Category.php

class Category extends Model
{
    use Searchable;

    protected $touches = [
        'places',];

    public function places()
    {
        return $this->belongsToMany(Place::class,'place_category');
    }
}

现在,我正在按类别搜索Place模型/数据过滤。如您所见,我还用toSearchableArray方法中的位置索引了类别。

我正在努力实现这样的目标。

Place::search($keyword)->whereIn('categories',????);//how can I filter by the Ids here

我该怎么做?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...