Save value from TextInput for sarch

Hey, is it possible to save a value typed in a TextInput (Form) to search something? I want to build a search and want to filter some relations. How can I do this?
6 Replies
Ilham Dimas Prayudha
Yes you can, first you need to make TextInput::make('search')->live, then render it in your livewire view component{{ $this->form }}, in your livewire component add this public ?array $data = []; public function mount(): void { $this->form->fill(); } then in your query do like this $products = Product::where('name', ,'like', '%' . $this->data['search'] . '%')->get(); customize form field and query logic as you need. Hope it's help!
GeRaged | Niklas
GeRaged | NiklasOP15mo ago
And how can I use the $products with a Select::make('products')
GeRaged | Niklas
GeRaged | NiklasOP15mo ago
Is there a complete example. I dont unterstand it. @ilhamdimasprayudha At the top public $query = null; TextInput::make('query') and at the bottom
Section::make('Attribute')
->schema(
$data->map(function ($attributes, $group) {

// I want to use the $query variable here!

return CheckboxList::make($group)
->options($attributes)
->visible();
}
)->toArray()
)
->columns(3)
Section::make('Attribute')
->schema(
$data->map(function ($attributes, $group) {

// I want to use the $query variable here!

return CheckboxList::make($group)
->options($attributes)
->visible();
}
)->toArray()
)
->columns(3)
This is the error Using $this when not in object context
Ilham Dimas Prayudha
Where you put TextInput::make('query')? Can I see your full code?
GeRaged | Niklas
GeRaged | NiklasOP15mo ago
<?php

namespace App\Filament\Resources\OperatorResource\Pages;

use App\Filament\Resources\OperatorResource;
use App\Models\Attribute;
use App\Models\Resort;
use Filament\Actions;
use Filament\Forms\Components\CheckboxList;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Resources\Pages\EditRecord;

class EditOperator extends EditRecord
{
protected static string $resource = OperatorResource::class;

protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}

public function form(Form $form): Form
{

$attributes = Attribute::whereAllowsModel(Resort::class)->get();
$data = $attributes->groupBy('group')->map(function ($item) {
return $item->pluck('name', 'id')->toArray();
});

return $form
->schema([
Section::make('Suche')
->schema([
Select::make('query')
->label('Gruppe')
->options(Attribute::whereAllowsModel(Resort::class)->select('group')->distinct()->get()->map(fn ($value) => $value['group']))
->searchable()
]),
Section::make('Attribute')
->schema(
$data->map(function ($attributes, $group) {
return CheckboxList::make($group)
->options($attributes)
->visible();
}
)->toArray()
)
->columns(3)
]);
}

}
<?php

namespace App\Filament\Resources\OperatorResource\Pages;

use App\Filament\Resources\OperatorResource;
use App\Models\Attribute;
use App\Models\Resort;
use Filament\Actions;
use Filament\Forms\Components\CheckboxList;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Resources\Pages\EditRecord;

class EditOperator extends EditRecord
{
protected static string $resource = OperatorResource::class;

protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}

public function form(Form $form): Form
{

$attributes = Attribute::whereAllowsModel(Resort::class)->get();
$data = $attributes->groupBy('group')->map(function ($item) {
return $item->pluck('name', 'id')->toArray();
});

return $form
->schema([
Section::make('Suche')
->schema([
Select::make('query')
->label('Gruppe')
->options(Attribute::whereAllowsModel(Resort::class)->select('group')->distinct()->get()->map(fn ($value) => $value['group']))
->searchable()
]),
Section::make('Attribute')
->schema(
$data->map(function ($attributes, $group) {
return CheckboxList::make($group)
->options($attributes)
->visible();
}
)->toArray()
)
->columns(3)
]);
}

}
I want multiple checkboxes but only with attributes where I selected the group from ...
Want results from more Discord servers?
Add your server