dpi96151 2017-11-12 19:09
浏览 127

Laravel 5.5 / Scout:如何扩展Scout以使用连接?

I am using Laravel/Scout/Elasticsearch via https://packagist.org/packages/babenkoivan/scout-elasticsearch-driver and I have this situation:

  1. To search, I must use a model like this:

    $visits = Visit::search("canada")->with(['origin', 'profile', 'user'])->paginate(10);

It works very well.

  1. As you can see, this model is related to three other tables: origins (that are countries), profile and users. The way the everything is set, I can search for "canada" and get all the visits that came from Canada, what is fine as well.
  2. The result is shown in a grid using paginate(), what works well, too.
  3. However, if I want to sort the grid by Origins -- for everything I read and tried so far -- I can't use the $model->with(...) approach. Instead, I have to use something like

    $visits = DB::table('visits') ->join('origins', 'origins.id', 'visits.origin_id') ->orderby($sort_column, $sort_az_za) ->paginate(10);

  4. This is the thing: the search() will not work with the DB::table('visits') syntax and Visit::search("canada")->with(....)... approach does not allow me to sort by a field that is not in the Visits table.

The question is: how can I search and sort the results by any field I want?

I thought that it should be possible to extend Scout to search DB::table('TABLE') or to try to sort directly via ES -- though I would prefer to keep all the code bound to the "Laravel way".

If extending the DB::table('TABLE') is a way, could someone point me where to start?

Other than that, any other ideas?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
    • ¥30 ppOCRLabel导出识别结果失败
    • ¥15 Centos7 / PETGEM
    • ¥15 csmar数据进行spss描述性统计分析
    • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
    • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
    • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
    • ¥15 运动想象脑电信号数据集.vhdr
    • ¥15 三因素重复测量数据R语句编写,不存在交互作用