Have you tried to use something like Laravel Scout? https://laravel.com/docs/5.4/scout
The order is important in this scenario so a fulltext index might suit you better.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am searching for items by entering something like 'D1234 GS0090' but in the database its stored as Item D1234 HEX SCREW GS0090 OI09 (its not always in the same order and I am searching multiple columns). Right now i can only search for D1234 HEX How can I search for multiple words?
My current query
$products = DB::connection('items')
->table('items')
->join('itemunits','itemunits.itemcode', '=', 'items.itemcode')
->join('vendoritems', 'vendoritems.itemcode', '=', 'items.itemcode')
->where('items.deleted', '=', 0)
->where('vendoritems.deleted', '=', 0)
->where('items.description', 'LIKE', '%'.$term.'%')
->orWhere('items.vendorcode', 'LIKE', '%'.$term.'%' )
->orWhere('items.vendordefaultcode','LIKE', '%'.$term.'%')
->orWhere('vendoritems.partnumber', 'LIKE', '%'.$term.'%')
->orWhere('vendoritems.partvendorcode', 'LIKE', '%'.$term.'%')
->get());
Please or to participate in this conversation.