searchable icon indicating copy to clipboard operation
searchable copied to clipboard

Posibble using $query->search() in whereHas query?

Open permadiwibisono opened this issue 6 years ago • 3 comments

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

permadiwibisono avatar Apr 05 '18 16:04 permadiwibisono

Same issue:

    $orderHistory = Order::whereHas('orderLines.product', function ($query) use($searchTerm) {
        $query->search($searchTerm, null, null, true);
    })

lperry65 avatar Apr 29 '18 17:04 lperry65

Same problem here

Roadirsh avatar Oct 03 '18 12:10 Roadirsh

You should use join for this purpose.

https://github.com/nicolaslopezj/searchable/blob/b1d24ea45f75e36a11a093efa46fe44c06dd10b7/README.md?plain=1#L42-L52

alanmatiasdev avatar May 08 '24 01:05 alanmatiasdev