Start with a simple search, then makes it more complex step by step.
Ask for help if you get stuck on one step by giving your code, sample data & expected result.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have 4 tables in my application. One main ItemLines table with 3 foreign keys that reference 3 other tables: ItemParent, ItemLines, and ShippingParent.
I'm finding it impossible to implement search. I want to give users a single search bar and let them search by sku (ItemLines table), order_id (ItemParent), name (ItemParent), or tracking_number (ShippingParent).
I'm using "like" syntax
'temLines::where(sku', 'like', '%' . $search_query . '%)' etc
I've tried all sorts of combinations of whereHas and where, but I haven't been able to get the results that I need.
What I'm hoping for is that when search is called, all of the fields that I want searched should be searched across all tables. If a match is found, the entire record with all relationships should be returned.
This is my current attempt:
public function order_search(string $search_query): array|Collection
{
return ItemLines::where('sku', 'like', '%' . $search_query . '%')
->with(['item_parent', 'products', 'shipping_parent'], function($query) use($search_query) {
$query->where('internal_order_id', 'like', '%' . $search_query . '%');
})
->get();
}
The error message is "message": "Illegal offset type", "exception": "TypeError",
Please or to participate in this conversation.