search for foreign key using multiple columns
hey all can anyone tell me how to make this work?
5 Replies
or at least to search using the barcode and to show the name of the product after selecting the barcode
Solution
public static function form(Form $form): Form
{
return $form
->schema([
Select::make('inventory_id')
->searchable()
->getSearchResultsUsing(fn (string $search): array => Inventory::where('productName', 'barcode', 'partNumber', "%{$search}%")->limit(50)->pluck('productName','id')->toArray())
->getOptionLabelsUsing(fn ($value): ?string => Inventory::find($value)?->productName),
]);
}
I tried it and I'm getting this error when searching: https://flareapp.io/share/W7zD2QAm
Flare
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%x%
productName
= ? limit 50' at line 1 (Connection: mysql, SQL: select productName
, id
from inventories
where %x% productName
= barcode limit 50)...Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.