Jellibloom
Jellibloom
FFilament
Created by Jellibloom on 3/31/2024 in #❓┊help
How to trigger an action from a TextColumn
Hello, how can we trigger an action from a table column? Here's my text column
Tables\Columns\TextColumn::make('status')
->translateLabel()
->badge()
->color(fn ($state) => $state->getColor())
->toggleable()
->sortable()
->searchable()->forceSearchCaseInsensitive()
->suffix(function ($state) {
if ($state === Enums\ReservationStatus::READY) {
return ' ('.__('Add booking review').')';
}
})
->action(function (Reservation $record, Table $table) {
info(1);
// how to trigger writeReview action
}),
Tables\Columns\TextColumn::make('status')
->translateLabel()
->badge()
->color(fn ($state) => $state->getColor())
->toggleable()
->sortable()
->searchable()->forceSearchCaseInsensitive()
->suffix(function ($state) {
if ($state === Enums\ReservationStatus::READY) {
return ' ('.__('Add booking review').')';
}
})
->action(function (Reservation $record, Table $table) {
info(1);
// how to trigger writeReview action
}),
And this is my action that I want to trigger
Tables\Actions\Action::make('writeReview')
->label(__('Booking review'))
->form([
Forms\Components\TextInput::make('review.rating')
->translateLabel()
->minValue(1)
->maxValue(10)
->step(1)
->numeric()
->required()
->default(fn ($record) => $record->review?->rating),
Forms\Components\Textarea::make('review.comment')
->translateLabel()
->default(fn ($record) => $record->review?->comment)
->helperText(fn ($record) => __(':name review', ['name' => $record->client?->name])),
])
->action(function (array $data, Reservation $record): void {
$record->review()->updateOrCreate([], $data['review']);
})
->hidden(true),
Tables\Actions\Action::make('writeReview')
->label(__('Booking review'))
->form([
Forms\Components\TextInput::make('review.rating')
->translateLabel()
->minValue(1)
->maxValue(10)
->step(1)
->numeric()
->required()
->default(fn ($record) => $record->review?->rating),
Forms\Components\Textarea::make('review.comment')
->translateLabel()
->default(fn ($record) => $record->review?->comment)
->helperText(fn ($record) => __(':name review', ['name' => $record->client?->name])),
])
->action(function (array $data, Reservation $record): void {
$record->review()->updateOrCreate([], $data['review']);
})
->hidden(true),
4 replies
FFilament
Created by Jellibloom on 3/27/2024 in #❓┊help
How to use same column attribute in a Table Filter AND in Listing records (Using tabs to filter)
Hello folks! We want to display a status attribute in table filters, and in list getTabs method but when filtering it's not working properly, as it filters data that has both status. I want to apply one filter of them; when choosing one, remove the another Here's how the url is displayed when choosing both filters http://localhost:8000/admin/bookings?activeTab=Ready&tableFilters[status][values][0]=Ready TIA
4 replies
FFilament
Created by Jellibloom on 3/26/2024 in #❓┊help
How to attach and detach a relation in case there were values
My resource may has One to One (Polymorphic) relationship with Review, I want to create a review if I wrote values and if it was null want to delete it if existed
Forms\Components\Fieldset::make(__('Booking review'))
//create only if there are values, if null delete
->relationship('review')
->schema([
Forms\Components\TextInput::make('rating')
->requiredWith('comment'),
Forms\Components\Textarea::make('comment')
->columnSpan(2),
])
->visibleOn('edit')
->visible(function (Forms\Get $get): bool {
return $get('status') === 'in review';
}),
Forms\Components\Fieldset::make(__('Booking review'))
//create only if there are values, if null delete
->relationship('review')
->schema([
Forms\Components\TextInput::make('rating')
->requiredWith('comment'),
Forms\Components\Textarea::make('comment')
->columnSpan(2),
])
->visibleOn('edit')
->visible(function (Forms\Get $get): bool {
return $get('status') === 'in review';
}),
I really appreciate your help folks, really thanks for helping others!
3 replies
FFilament
Created by Jellibloom on 3/25/2024 in #❓┊help
How to validate inside `handleRecordCreation()` or `mutateFormDataBeforeSave`
Hello guys, hope you're doing well! I want to validate or use a custom validation rule inside mutateFormDataBeforeSave(), wonder how to do that? Thanks in advance!
6 replies
FFilament
Created by Jellibloom on 3/19/2024 in #❓┊help
Filter enum value from select enum options (get all enum values but selected ones)
No description
5 replies