backpack laravel - searchLogic not working for select_multiple

190 Views Asked by At

SearchLogic for select_multiple isn't working, I can't change the type of the column so, I have to make it searchable. any workaround?

thanks in advance

I tried to make it to different type as well but getting datatables popup error there.

$this->crud->setColumns([
    [
        'name' => 'item',  
        'label' => trans('admin.item_number'),
        'type' => "select_multiple",
        'entity' => 'item', 
        'attribute' => "item_number",  
        'model' => "App\Item",
        'searchLogic' => function ($query, $column, $searchTerm)
        {
            $query->orWhereHas('item', function ($q) use ($column, $searchTerm,$value) {
                $q->join('download_item','download_item.download_id', '=' , 'downloads.id')
                ->join('items','download_item.item_id', '=' , 'items.id')
                ->where('items.item_number', 'like', '%'.$searchTerm.'%');
            });
        }  
    ],
]);

I have three tables and the relations are like downloads table have items from items table but the relationship store in different table named as download_item which contains download_id and item_id.

1

There are 1 best solutions below

1
slooffmaster On

Why not use a filter? That's much more useful for the user, IMHO.

Here's an example:

        $this->crud->addFilter([
            'name'  => 'provider_state',
            'type'  => 'select2_multiple',
            'label' => 'State',
        ], function () {
            return [
                'draft'           => 'Draft',
                'paid'            => 'Paid',
                'open'            => 'Open',
                'late'            => 'Late',
                'uncollectible'   => 'Uncollectible',
                'reminded'        => 'Reminded',
                'pending_payment' => 'Pending Payment',
            ];
        }, function ($values) {
            $this->crud->addClause('whereIn', 'provider_state', json_decode($values));
        });