searchable
searchable copied to clipboard
Posibble using $query->search() in whereHas query?
Like example I've two tables: carts:
- id
- product_id
- qty
products:
- id
- SKU
- name
- gender
- price
in Product.php
protected $searchable = [ 'columns' => [ 'products.name' => 16, 'products.SKU' => 7, ] ];
I'm using SearchableTrait in Product.php model. So it is possible to using this code:
$data= Cart::whereHas('product', function ($query) use($keyword){ $query->search($keyword); })->get();
I've got error Column not found: 'carts.product_id' in where clause
Same issue:
$orderHistory = Order::whereHas('orderLines.product', function ($query) use($searchTerm) {
$query->search($searchTerm, null, null, true);
})
Same problem here
You should use join for this purpose.
https://github.com/nicolaslopezj/searchable/blob/b1d24ea45f75e36a11a093efa46fe44c06dd10b7/README.md?plain=1#L42-L52