I have a ViewColumn in getTables and i have 3 columns inside this view how can i make it searchable
i am using like this is not working
ViewColumn::make('product_id')
->label('Product ID')
->sortable()
->searchable(query: function (Builder $query, string $search): Builder {
return $query
->where('asin', 'like', "%{$search}%")
->where('upc', 'like', "%{$search}%")
->where('fnsku', 'like', "%{$search}%");
})
->view('filament.tables.columns.product.product_id'),
6 Replies
Can you be a little more specific? What isn't working?
@Hugh Messenger I have a table in which i have created a view column like this ViewColumn::make('product_id') in above code and in product_id.blade.php file i am using 3 database columns in ul and li i want to make this searchable filter according these 3 db columns i am using the above code but it is not working
Your query is searching for rows where all three of those fields match the search term, with each one joined with AND. I suspect you need to use orWhere() for the second two, so they get joined with OR.
https://laravel.com/docs/10.x/queries#or-where-clauses
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.
@Hugh Messenger thanks you solved my problem stay blessed 😊
@aliabbas8356 hi sir can i see your view('filament.tables.columns.product.product_id'), sorry for tag
@daisy21 yes sure i will send you in a while
@daisy21 here is the code of product_id.blade.php
<div class="text-[10px] whitespace-normal ml-3">
@php
$asin = ($getRecord()->asin) ? $getRecord()->asin :' -';
$upc = ($getRecord()->upc ) ? $getRecord()->upc : ' -';
$fnsku = ($getRecord()->fnsku) ? $getRecord()->fnsku : ' -';
@endphp
@if($fnsku)
<ul class="max-w-md space-y-1 list-none list-inside ">
<li class="text-xs">
<strong>ASIN: </strong>{{$asin}}
</li>
<li class="text-xs">
<strong>FNSKU:</strong>{{$fnsku}}
</li>
<li class="text-xs">
<strong>UPC:</strong>{{$upc}}
</li>
</ul>
@endif
</div>