0

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.

  • Hmm what do you mean by "not working". What have you tried inside the `searchLogic` attribute, and what result or error are you getting? – tabacitu Feb 07 '23 at 11:48
  • @tabacitu, I'm using very old version of backpack and I have added searcLogic in setColumn but it's not seems to working – Paritosh Mehra Feb 07 '23 at 14:41
  • Sorry man, but I cannot help if you do not give more information. What exact version are you using? What is happening more exactly when you try? – tabacitu Feb 08 '23 at 15:51
  • @tabacitu, I am using "backpack/base": "^0.7.25", "backpack/generators": "^1.1","backpack/crud": "dev-**-intr**et", I have also edited my question for your reference, kindly let me know any other information required. Thank you. – Paritosh Mehra Feb 10 '23 at 12:55
  • Ouch... backpack/base 0.7 tells me you're probably using a very VERY old version of Backpack... probably 4-5 years old. And a branch of backpack/crud that... we do not have, and does not look familiar at all. So you might be using your own custom backpack/crud, from your own repo. I'm afraid I can't help with unsupported or custom versions of our software, sorry. To debug this further, I recommend you `dd()` inside that closure, after the query. Alternatively, it's possible that `searchLogic` didn't even exist back then. I really don't know. Sorry I can't be of more help. – tabacitu Feb 12 '23 at 15:56

1 Answers1

1

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));
        });