簡體   English   中英

Laravel背包自定義搜索邏輯

[英]Laravel backpack custom search logic

您好,我正在嘗試對使用背包生成的列進行排序和搜索。

由於默認情況下它不存在,我需要自己添加它,我嘗試搜索的列是我在選擇時創建的計算列:

 $this->crud->operation('list', function () {
            $this->crud->groupBy('email')
                ->select('*', DB::raw('count(*) as countedAttempts));
        });

    }

    protected function setupListOperation()
    {
        $this->crud->addColumn(['name' => 'countedAttempts', 'type' => 'text', 'label' => 'Total count',
            'orderable' => true,
            'searchLogic' => function ($query, $column, $searchTerm) {
                $query->orWhere('countedAttempts', 'like', '%'.$searchTerm.'%');
            },
            'orderLogic' => function ($query, $column, $columnDirection) {
                return $query->orderBy('countedAttempts', $columnDirection);
            },
        ]);

在添加附加操作並執行原始 select 后,這適用於 orderlogic,但對於搜索邏輯,我仍然收到錯誤:

未找到列:“where 子句”中的 1054 列“countedAttempts”未知

我需要做什么?

您不能在別名上使用 where,您必須使用 Have 子句。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM