ziolupo
ziolupo
Explore posts from servers
FFilament
Created by ziolupo on 10/22/2024 in #❓┊help
livewire with table inside form: now the form is not saving
Hi! I have a livewire compoenent that starting from a recor di displaying a table with some options that are selectable:
class ListExhibitions extends Component implements HasForms, HasTable
{
use InteractsWithForms;
use InteractsWithTable;

public Winery $winery;

public function mount(Winery $winery): void
{
$this->winery = $winery;
}

public function table(Table $table): Table
{
return $table
->recordClasses("padding-top-0")
->query(Exhibition::query()->where('active',1))
->columns([
Tables\Columns\TextColumn::make('country')->sortable(),
Tables\Columns\CheckboxColumn::make('AC')
->state(function (Exhibition $record): bool {
return $record->wineries->contains($this->winery) ? true : false;
})
->updateStateUsing(function (Exhibition $record, $state) {
if ($state) {
$record->wineries()->attach($this->winery->id);
} else {
$record->masterclass ? $record->masterclass->wineries()->detach($this->winery->id) : "";
$record->wineries()->detach($this->winery->id);
}
})
->label('P'),
]);
}
public function render(): View
{
return view('livewire.exhibitions.list-exhibitions');
}
}
class ListExhibitions extends Component implements HasForms, HasTable
{
use InteractsWithForms;
use InteractsWithTable;

public Winery $winery;

public function mount(Winery $winery): void
{
$this->winery = $winery;
}

public function table(Table $table): Table
{
return $table
->recordClasses("padding-top-0")
->query(Exhibition::query()->where('active',1))
->columns([
Tables\Columns\TextColumn::make('country')->sortable(),
Tables\Columns\CheckboxColumn::make('AC')
->state(function (Exhibition $record): bool {
return $record->wineries->contains($this->winery) ? true : false;
})
->updateStateUsing(function (Exhibition $record, $state) {
if ($state) {
$record->wineries()->attach($this->winery->id);
} else {
$record->masterclass ? $record->masterclass->wineries()->detach($this->winery->id) : "";
$record->wineries()->detach($this->winery->id);
}
})
->label('P'),
]);
}
public function render(): View
{
return view('livewire.exhibitions.list-exhibitions');
}
}
This component is working fine, it's attaching e detaching record as soon as the checkboxes are clicked. The problem is that if I put this livewire componet into a form... You cannot save the form anymore: clicking the save button is doing anything. Cancel button is working. I need help Thank you!
2 replies
TLCTuto's Laravel Corner
Created by ziolupo on 10/18/2024 in #🚀laravel
InfoList and RepeatableEntry
Dear all, I have a problem with InfoList and RepeatableEntry. Here the code
[...]
public function exhibitionInfolist(Infolist $infolist): Infolist
{
return $infolist
->record($this->winery)
->schema([
RepeatableEntry::make('exhibitions')
->schema([
InfoLists\Components\TextEntry::make('country')
->formatStateUsing(fn(string $state): HtmlString => new HtmlString(
"<div class='w-full fi-header-heading text-xl text-primary-600' >" . $state . "</div>"
))
->suffixAction(
Action::make('openMasterclass')
->modalHeading('Select Wine For Masterclass')
->label(function (Exhibition $ex) {
return $ex->name;
})
->button()
->form([
Forms\Components\Select::make('wine_id')
// ->options(fn () => Wine::all()->pluck('name', 'id'))
->options(function (Exhibition $exhibition) { // here I got the error, becouse is not Exhibition but Winery
return $exhibition->wines()->pluck('name', 'wine_id');
})
])
->hidden(fn(Exhibition $record): bool => !$record->isWineryinMasterclass($this->winery->id))
->action(function (array $data, $record): void {
$record->updateWineInMasterclass($data['wine_id'], $this->winery);
})
)
[...]
public function exhibitionInfolist(Infolist $infolist): Infolist
{
return $infolist
->record($this->winery)
->schema([
RepeatableEntry::make('exhibitions')
->schema([
InfoLists\Components\TextEntry::make('country')
->formatStateUsing(fn(string $state): HtmlString => new HtmlString(
"<div class='w-full fi-header-heading text-xl text-primary-600' >" . $state . "</div>"
))
->suffixAction(
Action::make('openMasterclass')
->modalHeading('Select Wine For Masterclass')
->label(function (Exhibition $ex) {
return $ex->name;
})
->button()
->form([
Forms\Components\Select::make('wine_id')
// ->options(fn () => Wine::all()->pluck('name', 'id'))
->options(function (Exhibition $exhibition) { // here I got the error, becouse is not Exhibition but Winery
return $exhibition->wines()->pluck('name', 'wine_id');
})
])
->hidden(fn(Exhibition $record): bool => !$record->isWineryinMasterclass($this->winery->id))
->action(function (array $data, $record): void {
$record->updateWineInMasterclass($data['wine_id'], $this->winery);
})
)
Inside the RepeatableEntry I can access the current "record" belonging to the relationship as it should be. The problem is inside the form element: here if I'm trying to access to the current record I got the record outside the RepeatableEntry (in this case $this->winery). How can I access to the "inner" record? Because my SELECT options depend on it. The "options" are changing for every different Exhibition. Thank you
3 replies
FFilament
Created by ziolupo on 5/3/2024 in #❓┊help
Filter on table went to fullpage in 3.2.70 filament release.
No description
6 replies
TLCTuto's Laravel Corner
Created by ziolupo on 1/26/2024 in #💡filament
Simple (modal) resource and mutateFormDataBeforeSave()
I have a problem with my simple resource. I need to mutate the data before saving, but it's not possible to use mutateFormDataBeforeSave() as I would do with normal resource. Any ideas? I would like to add the following code:
$data['user_id'] = Auth::user()->id;
$data['user_id'] = Auth::user()->id;
I could use the boot() method on the model, but I would prefer not to do that. Thank you ZioLupo
5 replies
FFilament
Created by ziolupo on 12/18/2023 in #❓┊help
Open modal with table for searching the right element
No description
14 replies
FFilament
Created by ziolupo on 11/3/2023 in #❓┊help
Repeater with only one record with Toggle active
No description
6 replies
FFilament
Created by ziolupo on 11/2/2023 in #❓┊help
Submit button inside section in livewire component
No description
6 replies
FFilament
Created by ziolupo on 10/23/2023 in #❓┊help
fileupload hang when I drop new image
No description
6 replies
FFilament
Created by ziolupo on 10/19/2023 in #❓┊help
Customize Repeater - like simple() but with 2 fields
Hi, is it possible to customize a repeater item? I would like to obtain the effect of simple() but with two fields (one select and one toggle) . Thank you
2 replies
FFilament
Created by ziolupo on 10/17/2023 in #❓┊help
Relationship with pivot
No description
2 replies
FFilament
Created by ziolupo on 10/7/2023 in #❓┊help
Error in extending tables
I would like to extend from Tables for creating my own class (in filament 3) I created an empty class: namespace App\Tables\Components; use Filament\Tables\Table; class MyTable extends Table{ } but if I try to use MyTable in this way in a resource file: public static function table(MyTable $table): MyTable I have this error: Declaration of App\Filament\Resources\ExhibitionResource::table(App\Tables\Components\MyTable $table): App\Tables\Components\MyTable must be compatible with Filament\Resources\Resource::table(Filament\Tables\Table $table): And I cannot understand why.
15 replies
FFilament
Created by ziolupo on 9/27/2023 in #❓┊help
Conditional widget based on RelationManager
I have a resource with two relationmanager: public static function getRelations(): array { return [ RelationManagers\ProposalRelationManager::class, RelationManagers\PartecipantsRelationManager::class, ]; } The problem is that I want to show different widgets, based on different table when I switch tab from one relation to the other. As showed above I have Proposal a Partecipant resource with different widgets Inside the edit page I have: protected function getHeaderWidgets(): array { return [ ProposalResource\Widgets\ProposalOverview::class, ]; } but of course it's ok when the I hit the "proposal Tab", but when I'm clicking the Partecipant tab, I would like to load another widget. Is this possible? Thank you!
3 replies