Pedroesca
Custom search in table
I have a little situation here:
When I get ONLY ONE record, I need to add it to the cart (that happens, I just have to refresh the page with F5 for it to be reflected);
When I search by other criteria, it gets them correctly but when I press the action row, IT ALWAYS ADDS THE FIRST record in the table.
I know I'm doing something wrong.
public function table(Table $table): Table
{
return $table
->query(function()
{
if ($this->tableSearch === '') {
return Product::query()->whereRaw('1 = 0');
} else {
$product = Product::get()
->where('barcode', '=', $this->tableSearch);
if ($product->count() === 1) {
$this->addToCart($product->first()->id);
$this->updateCart();
$this->resetTableSearch();
return Product::query()->whereRaw('1 = 0');
} else {
return Product::query()
->where('name', 'like', '%' . $this->tableSearch . '%')
->orWhere('barcode', 'like', '%' . $this->tableSearch . '%');
}
}
return Product::query();
})
->columns([
TextColumn::make('name')->searchable(),
TextColumn::make('barcode')->searchable(),
])
->actions([
Action::make('add-cart')
->button()
->action(function($record){
$this->addToCart($record->id);
//dd($record);
})
]);
}
1 replies
Searchable in select blade
Hola. Es posible que al blade del select:
<x-filament::input.wrapper>
<x-filament::input.select wire:model="status">
<option value="draft">Draft</option>
<option value="reviewing">Reviewing</option>
<option value="published">Published</option>
</x-filament::input.select>
</x-filament::input.wrapper>
se le pueda agregar la propiedad o método "searchable()" tal como se utiliza en un recurso de filament?
2 replies
beforeSave whith relations
I have the following process in beforeSave() of EditSale.php, in which I restore the stock (quantities) of products, before the records are saved, as indicated by the "beforeSave" hook, but it turns out that when entering this hook the data of the relationship (SaleDetails) has already been saved.
i.e. where do i get the original detail before it is saved? is there a hook for this? for these cases beforesave does not work.
11 replies