search for foreign key using multiple columns

public static function form(Form $form): Form
{
return $form
->schema([
Select::make('inventory_id')
->relationship('inventory', 'productName')
->relationship('inventory', 'barcode')
->relationship('inventory', 'partNumber')
->searchable()

]);
}
public static function form(Form $form): Form
{
return $form
->schema([
Select::make('inventory_id')
->relationship('inventory', 'productName')
->relationship('inventory', 'barcode')
->relationship('inventory', 'partNumber')
->searchable()

]);
}
hey all can anyone tell me how to make this work?
5 Replies
The Huntsman
The HuntsmanOP14mo ago
or at least to search using the barcode and to show the name of the product after selecting the barcode
The Huntsman
The HuntsmanOP14mo ago
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), ]); }
The Huntsman
The HuntsmanOP14mo ago

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),
]);
}

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)...
LeandroFerreira
LeandroFerreira14mo ago
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.
Want results from more Discord servers?
Add your server