Pablo Torres
Pablo Torres
FFilament
Created by Pablo Torres on 5/15/2024 in #❓┊help
How to use Export Action to export the data of a RichEditor column without the HTML tags.
No description
3 replies
FFilament
Created by Pablo Torres on 4/1/2024 in #❓┊help
Replicate action do not exclude passed attributes.
I have also tried passing an array of the attributes needed to be replicated... no luck.
ReplicateAction::make()
->action(function (LegacyClient $record) {
$data = $record->replicate([
'name',
'aka',
'address_line_one',
'address_line_two',
'address_line_three',
]);
$data->setTable('clients');
$data->save();
}),
ReplicateAction::make()
->action(function (LegacyClient $record) {
$data = $record->replicate([
'name',
'aka',
'address_line_one',
'address_line_two',
'address_line_three',
]);
$data->setTable('clients');
$data->save();
}),
2 replies
FFilament
Created by Pablo Torres on 1/23/2024 in #❓┊help
Custom text columns, calculated values, sum of related table values.
I ended with... works, if someone has any comment it will be much appreciated.
Tables\Columns\ColumnGroup::make('Deals', [
Tables\Columns\TextColumn::make('deals_count')
->label('Count')
->wrapHeader()
->counts('deals'),
Tables\Columns\TextColumn::make('deals.price')
->label('Price Each')
->wrapHeader()
->alignment(Alignment::End)
->listWithLineBreaks()
->money('gbp', divideBy: 100),
Tables\Columns\TextColumn::make('Price Sum')
->label('Price Sum')
->state(function (Booking $record): int {
return $record->deals->sum('price');
})
->wrapHeader()
->alignment(Alignment::End)
->money('gbp', divideBy: 100),
Tables\Columns\TextColumn::make('vat')
->label('VAT %')
->wrapHeader()
->alignment(Alignment::End)
->suffix('%'),
Tables\Columns\TextColumn::make('VAT £')
->label('VAT £')
->state(function (Booking $record): int {
$dealsPriceSum = $record->deals->sum('price');
$vat = $record->vat;
$totalSum = $dealsPriceSum * $vat / 100;
return $totalSum;
})
->wrapHeader()
->alignment(Alignment::End)
->money('gbp', divideBy: 100),
Tables\Columns\TextColumn::make('Price Sum + VAT')
->label('Price Sum + VAT')
->state(function (Booking $record): int {
$dealsPriceSum = $record->deals->sum('price');
$vat = $record->vat;
$totalSum = $dealsPriceSum + ($dealsPriceSum * $vat / 100);
return $totalSum;
})
->wrapHeader()
->alignment(Alignment::End)
->money('gbp', divideBy: 100),
])
->alignment(Alignment::Center)
->wrapHeader(),
Tables\Columns\ColumnGroup::make('Deals', [
Tables\Columns\TextColumn::make('deals_count')
->label('Count')
->wrapHeader()
->counts('deals'),
Tables\Columns\TextColumn::make('deals.price')
->label('Price Each')
->wrapHeader()
->alignment(Alignment::End)
->listWithLineBreaks()
->money('gbp', divideBy: 100),
Tables\Columns\TextColumn::make('Price Sum')
->label('Price Sum')
->state(function (Booking $record): int {
return $record->deals->sum('price');
})
->wrapHeader()
->alignment(Alignment::End)
->money('gbp', divideBy: 100),
Tables\Columns\TextColumn::make('vat')
->label('VAT %')
->wrapHeader()
->alignment(Alignment::End)
->suffix('%'),
Tables\Columns\TextColumn::make('VAT £')
->label('VAT £')
->state(function (Booking $record): int {
$dealsPriceSum = $record->deals->sum('price');
$vat = $record->vat;
$totalSum = $dealsPriceSum * $vat / 100;
return $totalSum;
})
->wrapHeader()
->alignment(Alignment::End)
->money('gbp', divideBy: 100),
Tables\Columns\TextColumn::make('Price Sum + VAT')
->label('Price Sum + VAT')
->state(function (Booking $record): int {
$dealsPriceSum = $record->deals->sum('price');
$vat = $record->vat;
$totalSum = $dealsPriceSum + ($dealsPriceSum * $vat / 100);
return $totalSum;
})
->wrapHeader()
->alignment(Alignment::End)
->money('gbp', divideBy: 100),
])
->alignment(Alignment::Center)
->wrapHeader(),
2 replies
FFilament
Created by Pablo Torres on 1/17/2024 in #❓┊help
Summary to calculate VAT if not exempt.
Thank you for help and time... I have followed your advice and now I have it working:
$booking = Booking::where('id', $this->getOwnerRecord()->getKey())->firstOrFail();
$booking = Booking::where('id', $this->getOwnerRecord()->getKey())->firstOrFail();
->summarize(
Summarizer::make()
->label('VAT')
->money('gbp', divideBy: 100)
->using(function (\Illuminate\Database\Query\Builder $query) {
$booking = Booking::where('id', $this->getOwnerRecord()->getKey())->firstOrFail();
$exemptFromVat = $booking->exempt_from_vat;
if (!$exemptFromVat) {
$vatValue = Setting::where('id', 1)->firstOrFail()->bookings_vat;
return $query->sum(DB::raw("price * $vatValue / 100"));
} else {
return 0;
}
})
)
->summarize(
Summarizer::make()
->label('VAT')
->money('gbp', divideBy: 100)
->using(function (\Illuminate\Database\Query\Builder $query) {
$booking = Booking::where('id', $this->getOwnerRecord()->getKey())->firstOrFail();
$exemptFromVat = $booking->exempt_from_vat;
if (!$exemptFromVat) {
$vatValue = Setting::where('id', 1)->firstOrFail()->bookings_vat;
return $query->sum(DB::raw("price * $vatValue / 100"));
} else {
return 0;
}
})
)
From: https://filamentphp.com/docs/3.x/panels/resources/relation-managers#importing-related-records Thank you Tim.
4 replies
FFilament
Created by Pablo Torres on 12/8/2023 in #❓┊help
In a table display custom text when column is null. Works on v2 but not on v3.
Hi, Implementing '->default('Not yet')' I get the following error: Could not parse 'Not yet': Failed to parse time string (Not yet) at position 0 (N): The timezone could not be found in the database
4 replies
FFilament
Created by Pablo Torres on 12/6/2023 in #❓┊help
Browser does not refresh on file save (Docker)
Working by adding the following on AppServiceProvider.php
public function boot(): void
{
Filament::registerRenderHook('panels::head.end', fn (): string => Blade::render('@vite ( [\'resources/css/app.css\',\'resources/js/app.js\'])'));

}
public function boot(): void
{
Filament::registerRenderHook('panels::head.end', fn (): string => Blade::render('@vite ( [\'resources/css/app.css\',\'resources/js/app.js\'])'));

}
Following: https://www.answeroverflow.com/m/1162045851183611945#solution-1162066119511789659 Thanks.
3 replies
FFilament
Created by Pablo Torres on 8/7/2023 in #❓┊help
FilamentPHP offline documentation.
Nice... I'll see how "friendly" is that.
7 replies
FFilament
Created by Pablo Torres on 8/7/2023 in #❓┊help
FilamentPHP offline documentation.
Thank you for the advice... I was looking for something more mobile-friendly.
7 replies
FFilament
Created by Pablo Torres on 8/2/2023 in #❓┊help
Tooltip available only if return has value.
Thank you @leandro_ferreira , Following your advice...
->tooltip(fn (Booking $record): ?string => $record->marked_ready_at ? "Maked READY at: {$record->marked_ready_at}" : null),
->tooltip(fn (Booking $record): ?string => $record->marked_ready_at ? "Maked READY at: {$record->marked_ready_at}" : null),
It works nicely. I hope you don't mind... I hope I'm learning the right way. The first "?" is there to check if a value type string is returned (date/time cast) The second "?" is there working with ":" checking if the value is returned, if yes I show my text and date/time otherwise empty Correct? Thank you.
5 replies
FFilament
Created by Pablo Torres on 7/31/2023 in #❓┊help
Conditionally hide action button.
Thank you so much... it worked nicely.
6 replies
FFilament
Created by Pablo Torres on 7/31/2023 in #❓┊help
Customizing data before saving
Thank you... I think I had my code wrong...
protected function mutateFormDataBeforeSave(array $data): array
{
if (!$this->record->is_ready) {
$data['marked_ready_at'] = now();
}

return $data;
}
protected function mutateFormDataBeforeSave(array $data): array
{
if (!$this->record->is_ready) {
$data['marked_ready_at'] = now();
}

return $data;
}
By default "is_ready" is false. So, I have to check if it is false: "if ( ! $this->record->is_ready) ..." not: "if ( $this->record->is_ready) ..." Thanks for your time.
9 replies
FFilament
Created by Pablo Torres on 7/31/2023 in #❓┊help
Customizing data before saving
Thanks... I'll look at that, just one question if you have the time, please. The "mutateFormDataBeforeSave" approach you consider not good for the case? Thanks. https://filamentphp.com/docs/2.x/admin/resources/editing-records#customizing-data-before-saving
9 replies
FFilament
Created by Pablo Torres on 7/31/2023 in #❓┊help
Customizing data before saving
and Hi, thank you for your time... I have done:
Forms\Components\Toggle::make('is_ready')
->reactive()
->afterStateUpdated(function (Closure $set, $state) {
$set('marked_ready_at', now());
}),
Forms\Components\DateTimePicker::make('marked_ready_at'),
Forms\Components\Toggle::make('is_ready')
->reactive()
->afterStateUpdated(function (Closure $set, $state) {
$set('marked_ready_at', now());
}),
Forms\Components\DateTimePicker::make('marked_ready_at'),
Works, but... I want the date time to be grabbed when the user saves the record. Like this, the time and date recorded is the one when the toggle was used.
9 replies
FFilament
Created by Pablo Torres on 7/25/2023 in #❓┊help
DateTimePicker: Error - Invalid datetime format
Correct, thanks... I just add the cast, it works now.
5 replies
FFilament
Created by Pablo Torres on 7/24/2023 in #❓┊help
Cents on DB how to show in money?
3 replies
FFilament
Created by Pablo Torres on 7/24/2023 in #❓┊help
Price - show as money but store in cents
Thanks, it works... I have updated adding to my Pages / Edit
protected function mutateFormDataBeforeSave(array $data): array
{
$data['price'] = $data['price'] * 100;

return $data;
}
protected function mutateFormDataBeforeSave(array $data): array
{
$data['price'] = $data['price'] * 100;

return $data;
}
Thank you
6 replies
FFilament
Created by Pablo Torres on 7/24/2023 in #❓┊help
Price - show as money but store in cents
I have added this mutator to my model
public function setPriceAttribute($value)
{
$this->attributes['price'] = $value * 100;
}
public function setPriceAttribute($value)
{
$this->attributes['price'] = $value * 100;
}
Seems to be working but, is it the FilamentPHP way? Thanks.
6 replies
FFilament
Created by Pablo Torres on 7/10/2023 in #❓┊help
Logger by Z3d0X - How to display the "old" properties (key/value) in the view?
6 replies
FFilament
Created by Pablo Torres on 6/28/2023 in #❓┊help
Form, Grid to have Sections on main area with side area.
For the record. I was not able to find any reference to Forms\Components\Group in the docs, here what worked for me.is
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Group::make()
->schema([
Forms\Components\TextInput::make('uuid')
->label('UUID')
->required()
->maxLength(36),
])
->columnSpan(['lg' => 2]),
Forms\Components\Group::make()
->schema([
Forms\Components\DateTimePicker::make('marked_ready_at')
->disabled(),
])
->columnSpan(['lg' => 1]),
])
->columns(3);
}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Group::make()
->schema([
Forms\Components\TextInput::make('uuid')
->label('UUID')
->required()
->maxLength(36),
])
->columnSpan(['lg' => 2]),
Forms\Components\Group::make()
->schema([
Forms\Components\DateTimePicker::make('marked_ready_at')
->disabled(),
])
->columnSpan(['lg' => 1]),
])
->columns(3);
}
Thanks
3 replies
FFilament
Created by Pablo Torres on 6/28/2023 in #❓┊help
Form, Grid to have Sections on main area with side area.
3 replies