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.
Actually I have this in place. On my form
Forms\Components\RichEditor::make('comment'),
Forms\Components\RichEditor::make('comment'),
On my exporter
ExportColumn::make('comment')
->state(function (Booking $record): string {
$commentsWithoutTags = strip_tags($record->comment);
return $commentsWithoutTags;
}),
ExportColumn::make('comment')
->state(function (Booking $record): string {
$commentsWithoutTags = strip_tags($record->comment);
return $commentsWithoutTags;
}),
The data is exported without tags but it has spaces where the tags were.
3 replies
FFilament
Created by Pablo Torres on 4/1/2024 in #❓┊help
Replicate action do not exclude passed attributes.
I need to replicate records from model 'LegacyClient' to model 'Client'. In the 'clients' table I do not need some attributes from 'legacy_clients'. Implementing '->excludeAttributes' does not work.
->actions([
Tables\Actions\ActionGroup::make([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),

ReplicateAction::make()
->excludeAttributes(['legacy_contacts_count', 'sector', 'data_record_creator', 'data_record_manager'])
->action(function (LegacyClient $record) {
$data = $record->replicate();
$data->setTable('clients');
$data->save();
}),

])
])
->actions([
Tables\Actions\ActionGroup::make([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),

ReplicateAction::make()
->excludeAttributes(['legacy_contacts_count', 'sector', 'data_record_creator', 'data_record_manager'])
->action(function (LegacyClient $record) {
$data = $record->replicate();
$data->setTable('clients');
$data->save();
}),

])
])
I get: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sector' in 'field list'. Any advice...? thanks.
2 replies
FFilament
Created by Pablo Torres on 3/29/2024 in #❓┊help
Send data from edit page to create page on a different resource.
Im using Laravel v10 and Filament PHP v3 I have the following models: Client LegacyClient I want to allow users to re-use the legacy client data to create a new client record. For this I want to create a form action that 'sends' the data from the form in EditLegacyClient.php page to the form in CreateClient.php page. On my EditLegacyClient.php page I have:
protected function getHeaderActions(): array
{
return [
// Recycle Legacy Client Data Action btn.
Action::make('recycle')
->label('New Client (Recyle)')
->action(function (array $data): void {
//Data from the form in EditLegacyClient.php
$name = $data['name'];
$telephone = $data['telephone'];

//Variables to be sent to the form in CreateClient.php page
$data['name'] = $name;
$data['telephone'] = $telephone;
})
->color('warning')
->icon('heroicon-s-arrow-path')
->requiresConfirmation()
->modalHeading('Create new client using Legacy Client data?')
->modalDescription('Confirm your intention to reuse this legacy client data to create a new client record.')
->modalSubmitActionLabel('New Client (Recyle)')
->visible(
fn () => in_array(Auth()->user()->role, ['SUPERADMIN', 'ADMIN', 'MANAGER', 'ASSOCIATE'])
),
];
}
protected function getHeaderActions(): array
{
return [
// Recycle Legacy Client Data Action btn.
Action::make('recycle')
->label('New Client (Recyle)')
->action(function (array $data): void {
//Data from the form in EditLegacyClient.php
$name = $data['name'];
$telephone = $data['telephone'];

//Variables to be sent to the form in CreateClient.php page
$data['name'] = $name;
$data['telephone'] = $telephone;
})
->color('warning')
->icon('heroicon-s-arrow-path')
->requiresConfirmation()
->modalHeading('Create new client using Legacy Client data?')
->modalDescription('Confirm your intention to reuse this legacy client data to create a new client record.')
->modalSubmitActionLabel('New Client (Recyle)')
->visible(
fn () => in_array(Auth()->user()->role, ['SUPERADMIN', 'ADMIN', 'MANAGER', 'ASSOCIATE'])
),
];
}
Can someone please help me on how can I send the data across from the form in EditLegacyClient.php page to the form in CreateClient.php page? Thanks...
1 replies
FFilament
Created by Pablo Torres on 1/23/2024 in #❓┊help
Summarize Sum do not work when using ->state()
Why summarize is not working?
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)
->searchable(isIndividual: true)
->sortable()
->toggleable(),
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)
->searchable(isIndividual: true)
->sortable()
->toggleable(),
Adding
->summarize(Sum::make())
->summarize(Sum::make())
I get:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Sum + VAT) as "FwZmbsGj3ZnDrmtk" from (select `bookings`.*, (select count(*) fro' at line 1
SELECT
sum(bookings.deals_count) AS "gJMaXg3YF2Y1Elu1",
sum(bookings.Price Sum + VAT) AS "FwZmbsGj3ZnDrmtk"
FROM
(
SELECT
`bookings`.*,
(
SELECT
count(*)
FROM
`deals`
WHERE
`bookings`.`id` = `deals`.`booking_id`
) AS `deals_count`
FROM
`bookings`
) AS `bookings`
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Sum + VAT) as "FwZmbsGj3ZnDrmtk" from (select `bookings`.*, (select count(*) fro' at line 1
SELECT
sum(bookings.deals_count) AS "gJMaXg3YF2Y1Elu1",
sum(bookings.Price Sum + VAT) AS "FwZmbsGj3ZnDrmtk"
FROM
(
SELECT
`bookings`.*,
(
SELECT
count(*)
FROM
`deals`
WHERE
`bookings`.`id` = `deals`.`booking_id`
) AS `deals_count`
FROM
`bookings`
) AS `bookings`
Thanks.
2 replies
FFilament
Created by Pablo Torres on 1/23/2024 in #❓┊help
Custom text columns, calculated values, sum of related table values.
Hi, I have: Model: Booking
public function deals(): hasMany
{
return $this->hasMany(Deal::class);
}
public function deals(): hasMany
{
return $this->hasMany(Deal::class);
}
Model: Deal
public function booking(): belongsTo
{
return $this->belongsTo(Booking::class);
}
public function booking(): belongsTo
{
return $this->belongsTo(Booking::class);
}
My booking view shows this table (part of it). I have some questions, please read the comments.
Tables\Columns\ColumnGroup::make('Deals', [

//Works as wanted, shows how many deals I have per booking.
Tables\Columns\TextColumn::make('deals_count')
->counts('deals'),

//Works as wanted, shows the price of each deal per booking
Tables\Columns\TextColumn::make('deals.price')
->label('Each Deal Price')
->listWithLineBreaks()
->money('gbp', divideBy: 100),

//How can I calculate the sum of all deals?
Tables\Columns\TextColumn::make('???')
->label('All Deals Prices Sum')
-???,

//Works as wanted (different VAT values are stored in the DB)
Tables\Columns\TextColumn::make('vat')
->label('VAT')
->suffix('%'),

//How can I calculate the sum of all deals plus the value of the VAT?
Tables\Columns\TextColumn::make('???')
->label('All Deals Prices Sum + VAT')
???,

])
Tables\Columns\ColumnGroup::make('Deals', [

//Works as wanted, shows how many deals I have per booking.
Tables\Columns\TextColumn::make('deals_count')
->counts('deals'),

//Works as wanted, shows the price of each deal per booking
Tables\Columns\TextColumn::make('deals.price')
->label('Each Deal Price')
->listWithLineBreaks()
->money('gbp', divideBy: 100),

//How can I calculate the sum of all deals?
Tables\Columns\TextColumn::make('???')
->label('All Deals Prices Sum')
-???,

//Works as wanted (different VAT values are stored in the DB)
Tables\Columns\TextColumn::make('vat')
->label('VAT')
->suffix('%'),

//How can I calculate the sum of all deals plus the value of the VAT?
Tables\Columns\TextColumn::make('???')
->label('All Deals Prices Sum + VAT')
???,

])
Please, any advice is much appreciated, Thank you, Pablo
2 replies
FFilament
Created by Pablo Torres on 1/17/2024 in #❓┊help
Summary to calculate VAT if not exempt.
Please, I have the following code in my DealsRelationManager.php in my Bookings edit page.
Tables\Columns\TextColumn::make('price')
->money('gbp', divideBy: 100)
->searchable(isIndividual: true)
->sortable()

->summarize(Sum::make()
->label('Sub Total')
->money('gbp', divideBy: 100))

->summarize(
Summarizer::make()
->label('VAT')
->money('gbp', divideBy: 100)
->using(function (\Illuminate\Database\Query\Builder $query) {
$booking = Booking::where('id', 2)->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;
}
})
)
Tables\Columns\TextColumn::make('price')
->money('gbp', divideBy: 100)
->searchable(isIndividual: true)
->sortable()

->summarize(Sum::make()
->label('Sub Total')
->money('gbp', divideBy: 100))

->summarize(
Summarizer::make()
->label('VAT')
->money('gbp', divideBy: 100)
->using(function (\Illuminate\Database\Query\Builder $query) {
$booking = Booking::where('id', 2)->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;
}
})
)
I need to update the code so the hard-coded id '2' In line: $booking = Booking::where('id', 2)->firstOrFail(); is dynamically loaded. Any suggestions, thanks."
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.
This works on v2 but not on v3, any suggestions, please? On Filament v2 When the column 'marked_ready_at' does not yet have a date (is null) it shows 'Not yet'. Otherwise, it shows the date in a human-friendly way. On Filament v3 It doesn't work. Model
protected $casts = [
'marked_ready_at' => 'datetime',
];
protected $casts = [
'marked_ready_at' => 'datetime',
];
Filament resource
Tables\Columns\TextColumn::make('marked_ready_at')
->dateTime('M j, y')
->description(fn (Booking $record): string => $record->marked_ready_at?->since() ?? 'Not yet')
Tables\Columns\TextColumn::make('marked_ready_at')
->dateTime('M j, y')
->description(fn (Booking $record): string => $record->marked_ready_at?->since() ?? 'Not yet')
Does anyone have the update or perhaps a better approach to achieve it? PHP v8.2 Thank you.
4 replies
FFilament
Created by Pablo Torres on 12/6/2023 in #❓┊help
Browser does not refresh on file save (Docker)
Please, anyone using Docker (macOS) my browser is not refreshing automatically. I have done the following: File: vite.config.js
import { defineConfig } from 'vite';
import laravel, { refreshPaths } from 'laravel-vite-plugin';

export default defineConfig({
plugins: [
laravel({
input: [
'resources/css/app.css',
'resources/js/app.js'],
refresh: [
...refreshPaths,
'app/Livewire/**',
],
}),
],
});
import { defineConfig } from 'vite';
import laravel, { refreshPaths } from 'laravel-vite-plugin';

export default defineConfig({
plugins: [
laravel({
input: [
'resources/css/app.css',
'resources/js/app.js'],
refresh: [
...refreshPaths,
'app/Livewire/**',
],
}),
],
});
File: tailwind.config.js
/** @type {import('tailwindcss').Config} */
export default {
content: [
'./app/Filament/**/*.php',
'./resources/views/filament/**/*.blade.php',
'./vendor/filament/**/*.blade.php',
],
theme: {
extend: {},
},
plugins: [],
}
/** @type {import('tailwindcss').Config} */
export default {
content: [
'./app/Filament/**/*.php',
'./resources/views/filament/**/*.blade.php',
'./vendor/filament/**/*.blade.php',
],
theme: {
extend: {},
},
plugins: [],
}
I'm using: Laravel v10 Filament v3 (new project/fresh install) Docker macOS Safari I do run: 'sail npm run dev', when saving a file (Filament file eg. app/Filament/Resources/UserResource.php) on the terminal I get:
12:17:40 PM [vite] page reload app/Filament/Resources/UserResource.php
12:17:40 PM [vite] page reload app/Filament/Resources/UserResource.php
Unfortunately, my browser does not auto-refresh. Any ideas, thank you. Pablo
3 replies
FFilament
Created by Pablo Torres on 8/7/2023 in #❓┊help
FilamentPHP offline documentation.
Hi, I'm preparing for holidays. Does anyone know where/how I can get the FilamentPHP documentation offline or in pdf? Or somehow to be able to read with no Internet? Thank you.
7 replies
FFilament
Created by Pablo Torres on 8/5/2023 in #❓┊help
Calendar instead of input field in "dateTime" searchable as individual columns.
4 replies
FFilament
Created by Pablo Torres on 8/2/2023 in #❓┊help
Tooltip available only if return has value.
On my table, I have this code to show a tooltip.
->tooltip(fn ($record): string => "Marked READY at: {$record->marked_ready_at}")
->tooltip(fn ($record): string => "Marked READY at: {$record->marked_ready_at}")
If the record has been marked READY the tooltip shows, eg: Marked READY at: 2023-08-01 15:34:00 But if the record has not yet been marked as READY (null), the tooltip shows: Marked READY at: I would like to have the tooltip available only when there is a date/time to show up. Is there anything to show the tooltip only when the return data is not null? Thank you.
5 replies
FFilament
Created by Pablo Torres on 7/31/2023 in #❓┊help
Conditionally hide action button.
I have created an Action. Everything is working fine with the code below. When the action button is used the modal appears, and after confirming 'marked_ready_at' gets the current date/time.
protected function getActions(): array
{
return [
Action::make('Mark Ready')
->action(function (array $data): void {
$this->record->marked_ready_at = now();
$this->record->save();
$this->refreshFormData([
'marked_ready_at',
]);
})
->requiresConfirmation()
->modalHeading('Booking Ready')
->modalSubheading('Are you sure.')
->modalButton('Yes, it\'s ready'),
Actions\ViewAction::make(),
Actions\DeleteAction::make(),
];
}
protected function getActions(): array
{
return [
Action::make('Mark Ready')
->action(function (array $data): void {
$this->record->marked_ready_at = now();
$this->record->save();
$this->refreshFormData([
'marked_ready_at',
]);
})
->requiresConfirmation()
->modalHeading('Booking Ready')
->modalSubheading('Are you sure.')
->modalButton('Yes, it\'s ready'),
Actions\ViewAction::make(),
Actions\DeleteAction::make(),
];
}
I want to hide or disable the action button "Mark Ready" when "marked_ready_at" has a date/time. Any suggestion on how I can achieve this? Thanks.
6 replies
FFilament
Created by Pablo Torres on 7/31/2023 in #❓┊help
Customizing data before saving
On my BD I have:
$table->boolean('is_ready')->default(false);
$table->dateTime('marked_ready_at')->nullable();
$table->boolean('is_ready')->default(false);
$table->dateTime('marked_ready_at')->nullable();
On my form, I have:
Forms\Components\Toggle::make('is_ready'),
Forms\Components\Toggle::make('is_ready'),
In my model, I have:
protected $casts = [
'marked_ready_at' => 'datetime',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
protected $casts = [
'marked_ready_at' => 'datetime',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
I want when the toggle is used the 'marked_ready_at' to automatically grab the current date/time. I have tried the following: On my Pages/Edit
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;
}
What I/m doing wrong? Is there a better approach? Thanks.
9 replies
FFilament
Created by Pablo Torres on 7/25/2023 in #❓┊help
DateTimePicker: Error - Invalid datetime format
Hi, I have column "payment_due_at" , $table->dateTime('payment_due_at')->nullable(); My form:
Forms\Components\DateTimePicker::make('payment_due_at')
->displayFormat('M j, Y')
->format('Y-m-d h:m:s')
->maxDate(now()->addDays(90)),
Forms\Components\DateTimePicker::make('payment_due_at')
->displayFormat('M j, Y')
->format('Y-m-d h:m:s')
->maxDate(now()->addDays(90)),
When submitting I get: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '1690542420' for column 'payment_due_at' at row 1 I have also tried:
Forms\Components\DateTimePicker::make('payment_due_at')
->displayFormat('M j, Y')
->maxDate(now()->addDays(90)),
Forms\Components\DateTimePicker::make('payment_due_at')
->displayFormat('M j, Y')
->maxDate(now()->addDays(90)),
Same error Any suggestions, please? Thank you
5 replies
FFilament
Created by Pablo Torres on 7/24/2023 in #❓┊help
Cents on DB how to show in money?
I have a column "price" datatype INT I'm storing my prices in cents, eg: 1658460 My form looks like this:
Forms\Components\TextInput::make('price')
->mask(fn (Forms\Components\TextInput\Mask $mask) => $mask->money(prefix: '£', thousandsSeparator: ',', decimalPlaces: 2, isSigned: false))
->required(),
Forms\Components\TextInput::make('price')
->mask(fn (Forms\Components\TextInput\Mask $mask) => $mask->money(prefix: '£', thousandsSeparator: ',', decimalPlaces: 2, isSigned: false))
->required(),
How can I have my form show £16,584.60 and not £1,658,460.00, somewhere I need to divide the price by 100, where/how? Thanks.
3 replies
FFilament
Created by Pablo Torres on 7/24/2023 in #❓┊help
Price - show as money but store in cents
I have a column "price" datatype INT I want to store the price in cents My form looks like, I'm implementing the money() method:
Forms\Components\TextInput::make('price')
->mask(fn (Forms\Components\TextInput\Mask $mask) => $mask->money(prefix: '£', thousandsSeparator: ',', decimalPlaces: 2, isSigned: false))
->required(),
Forms\Components\TextInput::make('price')
->mask(fn (Forms\Components\TextInput\Mask $mask) => $mask->money(prefix: '£', thousandsSeparator: ',', decimalPlaces: 2, isSigned: false))
->required(),
My table
Tables\Columns\TextColumn::make('price')
->money('gbp'),
Tables\Columns\TextColumn::make('price')
->money('gbp'),
When saving eg: £16,584.60 On the DB gets stored 16585 instead of 1658460 How can I have my form show £16,584.60 but when saving store in cents? 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.
I have a form a want to display in like a main area with a side area. Like this sample: https://demo.filamentphp.com/shop/products/1/edit?activeRelationManager=0 I have the following code, what I'm doing wrong...?
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Grid::make([
'md' => 3,
])
->schema([
Forms\Components\Section::make('Name')
->schema([
Forms\Components\TextInput::make('name'),
])
->columns(2),
Forms\Components\Section::make('Date')
->schema([
Forms\Components\DatePicker::make('created_at'),
])
->columns(1),
]),
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Grid::make([
'md' => 3,
])
->schema([
Forms\Components\Section::make('Name')
->schema([
Forms\Components\TextInput::make('name'),
])
->columns(2),
Forms\Components\Section::make('Date')
->schema([
Forms\Components\DatePicker::make('created_at'),
])
->columns(1),
]),
]);
}
The above code gives me the sections stacked and not "Name" on the left (2 columns) and "Date" on the right (in one column). Thank you for your help.
3 replies
FFilament
Created by Pablo Torres on 6/23/2023 in #❓┊help
How to avoid extra queries created when related data is displayed?
3 replies
FFilament
Created by Pablo Torres on 6/23/2023 in #❓┊help
Timestamps datatype, applied ->since(), error: Call to a member function since() on string
I have some dates (timestamps data type) that when implementing:
Tables\Columns\TextColumn::make('payment_due_at')
->dateTime('M j, Y')
->description(fn (Booking $record): string => $record->payment_due_at->since()),
Tables\Columns\TextColumn::make('payment_due_at')
->dateTime('M j, Y')
->description(fn (Booking $record): string => $record->payment_due_at->since()),
I get:
Call to a member function since() on string
Call to a member function since() on string
In my model, I have implemented... (found in Laravel docs.)
/**
* The storage format of the model's date columns.
*
* @var string
*/
protected $dateFormat = 'U';


/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = [
'payment_due_at',
'created_at',
'updated_at',
];
/**
* The storage format of the model's date columns.
*
* @var string
*/
protected $dateFormat = 'U';


/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = [
'payment_due_at',
'created_at',
'updated_at',
];
Any suggestions, please? Thank you!
4 replies