Shavik
Shavik
FFilament
Created by Shavik on 5/30/2024 in #❓┊help
Table Summary Color
I would like to set the color of a table summary. I searched the docs and discord but couldn't find anything about it. Example: If the summary (total) is above 100%, I'd like the summary to be red. Anyone done something like this?
3 replies
FFilament
Created by Shavik on 3/29/2024 in #❓┊help
SelectFIlter & AsEnumCollection
No description
18 replies
FFilament
Created by Shavik on 12/12/2023 in #❓┊help
Nullable PHP Enum in Table TextColumn Oddity
No description
45 replies
FFilament
Created by Shavik on 11/15/2023 in #❓┊help
PHP Enum "Inheritance " in Filament
First off, I know you can't extend an enum in PHP, I'm trying to figure a way to accomplush that functionality though for the Filament getLabel, etc methods. Lets say I have a base "Laravel" package that has among other things, an enum. It's a plain 'ol, string backed enum. Nothing fancy. If I then have a Filament plugin (package) that wants to use that enum, PHP lacking enum inheritance strikes again. Does anyone have any preferred 'tricks' for 'extending (but not really)' an enum in this Filament package so that it has the getLabel, getColor, etc methods? For example, the base Laravel package would have no Filament dependencies. It could have an enum like
enum BaseStatus: string {
case Success = 'success';
}
enum BaseStatus: string {
case Success = 'success';
}
and in the Filament plugin that uses it, I'd like to have some way to 'add' the getLabel, etc to it. In a dream world:
enum Status: string extends BaseStatus {
// Cases are carried over from the base
public function getLabel() {
// ...
}
}
enum Status: string extends BaseStatus {
// Cases are carried over from the base
public function getLabel() {
// ...
}
}
Been scratching my head at a clean way to solve this for a day or two. Just didn't know if anyone else had encountered this or knew of a good way to handle it. Thanks!
8 replies
FFilament
Created by Shavik on 10/24/2023 in #❓┊help
Attach Action - Debounce Setting
Is there a way to set the debounce time for the attach action on a relation manager?
2 replies
FFilament
Created by Shavik on 10/20/2023 in #❓┊help
Notifications / Page Events from Laravel Job
No description
8 replies
FFilament
Created by Shavik on 10/18/2023 in #❓┊help
Table Summarizer Bug on PostgreSQL
So I have a table column defined as such:
Tables\Columns\TextColumn::make('price')
->money()
// Old simple way
// ->summarize(Sum::make()->money()->label('Total Price')),
// New Way with custom query
->summarize(
Summarizer::make()
->label('Total')
->money()
->using(fn (\Illuminate\Database\Query\Builder $query) => $query->sum(DB::raw('price * quantity'))),
Tables\Columns\TextColumn::make('price')
->money()
// Old simple way
// ->summarize(Sum::make()->money()->label('Total Price')),
// New Way with custom query
->summarize(
Summarizer::make()
->label('Total')
->money()
->using(fn (\Illuminate\Database\Query\Builder $query) => $query->sum(DB::raw('price * quantity'))),
I had asked yesterday how do to this price * quantity calculation but I was getting this error: SQLSTATE[42601]: Syntax error: 7 ERROR: zero-length delimited identifier at or near """" The query that is generated is
SELECT
sum(price * quantity) AS aggregate
FROM
(
SELECT
"line_items".*
FROM
"line_items"
INNER JOIN "invoices" ON "invoices"."id" = "line_items"."invoice_id"
WHERE
"invoices"."requisition_id" = 1
) AS ""
SELECT
sum(price * quantity) AS aggregate
FROM
(
SELECT
"line_items".*
FROM
"line_items"
INNER JOIN "invoices" ON "invoices"."id" = "line_items"."invoice_id"
WHERE
"invoices"."requisition_id" = 1
) AS ""
Clearly it's the last line ) AS "". I dug into the Summarizer.php file on line 108. $query = DB::table($query->toBase()); I haven't really looked at the source code for any of the Filament query stuff before it I changed the line to $query = DB::table($query->toBase(), 'test'); The above code now works. I'm not saying the table alias needs to be 'test' but I just needed a name to try. I'm not really sure what the best practice (naming) for this would be but I might also cross post this as a GitHub issue. Just wasn't sure if there was something else on the 'user' side (me, the dev) that I need to do to get this working? (since it also seems like a postgres quirk)
36 replies
FFilament
Created by Shavik on 10/17/2023 in #❓┊help
Table Column Summary using Quantity
No description
12 replies
FFilament
Created by Shavik on 9/18/2023 in #❓┊help
->fillForm is very slow in tests
I'm working on writing some feature/integration tests a simple Filament App. It tracks 'people'. I have the following test that should test that a user can be created. My problem is the ->fillForm method is very slow. It takes around 20 seconds to run. This code look scarier than it should as I've broken many things down to time them.
it('can create person', function () {
$personData = Person::factory()->make();
$personData->load('physicalAddress');

$addressData = Address::factory()->type(AddressType::PHYSICAL)->make();
$formData = array_merge($personData->toArray(), ['physicalAddress' => $addressData->toArray()]);
if ($personData->height_inches !== null) {
$formData['feet'] = (int)floor($personData->height_inches / 12);
$formData['inches'] = $personData->height_inches % 12;
}
dump($formData);

dump('performing livewire request.');
$livewire = livewire(PersonResource\Pages\CreatePerson::class);

DB::connection()->enableQueryLog();
$start = microtime(true);
$livewire->fillForm($formData);
dump('fillForm: ' . round((microtime(true) - $start), 2) . " seconds");


$start = microtime(true);
$livewire->call('create');
dump('call: ' . round((microtime(true) - $start), 2) . " seconds");

$start = microtime(true);
$livewire->assertHasNoFormErrors();
dump('assertHasNoFormErrors: ' . round((microtime(true) - $start), 2) . " seconds");

$queries = DB::getRawQueryLog();
dump($queries);

dump('checking database...');
$this->assertDatabaseHas(Person::class, $personData->withoutRelations()->toArray());
$addressData->setAppends([]);
$this->assertDatabaseHas(Address::class, $addressData->toArray());
});
it('can create person', function () {
$personData = Person::factory()->make();
$personData->load('physicalAddress');

$addressData = Address::factory()->type(AddressType::PHYSICAL)->make();
$formData = array_merge($personData->toArray(), ['physicalAddress' => $addressData->toArray()]);
if ($personData->height_inches !== null) {
$formData['feet'] = (int)floor($personData->height_inches / 12);
$formData['inches'] = $personData->height_inches % 12;
}
dump($formData);

dump('performing livewire request.');
$livewire = livewire(PersonResource\Pages\CreatePerson::class);

DB::connection()->enableQueryLog();
$start = microtime(true);
$livewire->fillForm($formData);
dump('fillForm: ' . round((microtime(true) - $start), 2) . " seconds");


$start = microtime(true);
$livewire->call('create');
dump('call: ' . round((microtime(true) - $start), 2) . " seconds");

$start = microtime(true);
$livewire->assertHasNoFormErrors();
dump('assertHasNoFormErrors: ' . round((microtime(true) - $start), 2) . " seconds");

$queries = DB::getRawQueryLog();
dump($queries);

dump('checking database...');
$this->assertDatabaseHas(Person::class, $personData->withoutRelations()->toArray());
$addressData->setAppends([]);
$this->assertDatabaseHas(Address::class, $addressData->toArray());
});
The output is the following:
"performing livewire request." // tests/Feature/PersonTest.php:43
"fillForm: 20.66 seconds" // tests/Feature/PersonTest.php:54
"call: 0.44 seconds" // tests/Feature/PersonTest.php:59
"assertHasNoFormErrors: 0.4 seconds" // tests/Feature/PersonTest.php:63
array:5 [ // tests/Feature/PersonTest.php:66
0 => array:2 [
"raw_query" => "insert into "people" ("first_name", "middle_name", "last_name", "maternal_last_name", "gender", "birthday", "place_of_birth", "weight_pounds", "eye_color", "hair_color", "email", "home_phone", "cell_phone", "marketing_comms_enabled", "update_comms_enabled", "user_id", "updated_at", "created_at") values ('Zoey', null, 'Rath', 'McLaughlin', 'female', '1926-07-06', 'Corkeryfurt', 152, null, null, 'waters.mable@example.net', '(914) 319-7774', '+1-316-757-2317', 0, 0, 1, '2023-09-18 22:19:37', '2023-09-18 22:19:37')"
"time" => 0.09
]
1 => array:2 [
"raw_query" => "insert into "addresses" ("type", "street", "suite", "city", "state", "zip", "updated_at", "created_at") values ('physical', '700 Gustave Light Suite 860', null, 'Port Devon', 'MO', '87688', '2023-09-18 22:19:37', '2023-09-18 22:19:37')"
"time" => 0.07
]
2 => array:2 [
"raw_query" => "update "people" set "physical_address_id" = 1, "updated_at" = '2023-09-18 22:19:37' where "id" = 1"
"time" => 0.04
]
3 => array:2 [
"raw_query" => "insert into "addresses" ("type", "street", "suite", "city", "state", "zip", "updated_at", "created_at") values ('mailing', null, null, null, null, null, '2023-09-18 22:19:37', '2023-09-18 22:19:37')"
"time" => 0.04
]
4 => array:2 [
"raw_query" => "update "people" set "mailing_address_id" = 2, "updated_at" = '2023-09-18 22:19:37' where "id" = 1"
"time" => 0.03
]
]
"checking database..." // tests/Feature/PersonTest.php:68

PASS Tests\Feature\PersonTest
"performing livewire request." // tests/Feature/PersonTest.php:43
"fillForm: 20.66 seconds" // tests/Feature/PersonTest.php:54
"call: 0.44 seconds" // tests/Feature/PersonTest.php:59
"assertHasNoFormErrors: 0.4 seconds" // tests/Feature/PersonTest.php:63
array:5 [ // tests/Feature/PersonTest.php:66
0 => array:2 [
"raw_query" => "insert into "people" ("first_name", "middle_name", "last_name", "maternal_last_name", "gender", "birthday", "place_of_birth", "weight_pounds", "eye_color", "hair_color", "email", "home_phone", "cell_phone", "marketing_comms_enabled", "update_comms_enabled", "user_id", "updated_at", "created_at") values ('Zoey', null, 'Rath', 'McLaughlin', 'female', '1926-07-06', 'Corkeryfurt', 152, null, null, 'waters.mable@example.net', '(914) 319-7774', '+1-316-757-2317', 0, 0, 1, '2023-09-18 22:19:37', '2023-09-18 22:19:37')"
"time" => 0.09
]
1 => array:2 [
"raw_query" => "insert into "addresses" ("type", "street", "suite", "city", "state", "zip", "updated_at", "created_at") values ('physical', '700 Gustave Light Suite 860', null, 'Port Devon', 'MO', '87688', '2023-09-18 22:19:37', '2023-09-18 22:19:37')"
"time" => 0.07
]
2 => array:2 [
"raw_query" => "update "people" set "physical_address_id" = 1, "updated_at" = '2023-09-18 22:19:37' where "id" = 1"
"time" => 0.04
]
3 => array:2 [
"raw_query" => "insert into "addresses" ("type", "street", "suite", "city", "state", "zip", "updated_at", "created_at") values ('mailing', null, null, null, null, null, '2023-09-18 22:19:37', '2023-09-18 22:19:37')"
"time" => 0.04
]
4 => array:2 [
"raw_query" => "update "people" set "mailing_address_id" = 2, "updated_at" = '2023-09-18 22:19:37' where "id" = 1"
"time" => 0.03
]
]
"checking database..." // tests/Feature/PersonTest.php:68

PASS Tests\Feature\PersonTest
As you can see, there are no slow queries and I've isolated the slowness to the ->fillForm method. I can't see to figure out why that would be slowing things down to badly. Any help would be greatly appreciated!
28 replies
FFilament
Created by Shavik on 8/17/2023 in #❓┊help
Login Page Blade Override
I'm looking for the proper way to override the default login blade? I'm attempting to get the v3 Filament Socialite package up and running and it's instructions are a bit out of date. It says publish the views and update the login but for one, the v3 docs recommend not publishing all view and even when I tried that, the login.blade.php isn't one of the ones generated. I copied that blade from the vendor directory into my project but I'm unsure of how to properly configure Filament to use that new login blade. Thanks!
16 replies
FFilament
Created by Shavik on 8/10/2023 in #❓┊help
Date/Time Picker Required
When adding a DatePicker or DateTime Picker to a form (a form on a Livewire component), the ->required() option isn't ensuring the field is filled out. The user can still submit the form and null is submitted on the back end. Having a similar but worse issue with the Flatpickr plugin (which is why we went back tothe base component) where it always submits null no matter if you pick a date/time or not. Thanks for any insight!
21 replies
FFilament
Created by Shavik on 8/7/2023 in #❓┊help
Widget Color()
26 replies
FFilament
Created by Shavik on 8/7/2023 in #❓┊help
Autofocus in a Modal
Is there anyway to get the autofocus to work on input fields in slideovers/modals? It currently doesn't focus the field when opening a modal or slideover but does work on the full page form.
13 replies
FFilament
Created by Shavik on 8/5/2023 in #❓┊help
NavigationGroup & Page Order
I've had good luck sorting my navigation items as well as grouping some and ordering the groups. My problem is that the pages all come before the groups, no matter the sort order. Will I need to do a completely custom navigation to accomplish this?
3 replies
FFilament
Created by Shavik on 8/4/2023 in #❓┊help
Adding Button/Action to Panel Header
Is there mechanism to have (one or many) buttons added to the header of a panel (all pages/resources)? Thanks!
7 replies
FFilament
Created by Shavik on 8/3/2023 in #❓┊help
TailwindCSS in Livewire components used in Filament Pages
I have added a custom Livewire component that I'm using in a Filament page. It's working well but I can't seem to get any of my tailwindd classes to do anything. I have installed tailwind and set it up according to the docks. In the rendered code I see my tailwind class but it doesn't appear that it knows what it is. Is there anything else I need to do to get things working? Not sure if this is a Filament or a Livewire issue or something else entirely. New to both. Thanks for any help!
64 replies
FFilament
Created by Shavik on 8/2/2023 in #❓┊help
Markdown Preview
Per the docs here, https://filamentphp.com/docs/3.x/forms/fields/markdown-editor It states:
The markdown editor allows you to edit and preview markdown content, as well as upload images using drag and drop.
The markdown editor allows you to edit and preview markdown content, as well as upload images using drag and drop.
I can't seem to find anyway to enable the 'preview' that it's talking about. Is that not talking about 'live preview' of sorts?
8 replies
FFilament
Created by Shavik on 8/2/2023 in #❓┊help
Unexpected Behavior from mutateFormDataBeforeCreate
Working on a little test learning Filament project. It is an issue tracker. I have made an Issue model/resource, etc. The issue has a user_id that is the user that created the issue. I have the select box working on the resource that shows the users in the dropdown, etc. That works great. I was trying to implement it so that if a user isn't selected, it will just pick the currently logged in user when saving. I searched discord here and found an old post where they linked to the website and it mentioned adding
protected function mutateFormDataBeforeCreate(array $data): array
{
if (empty($data['user_id'])) {
$data['user_id'] = auth()->id();
}

return $data;
}
protected function mutateFormDataBeforeCreate(array $data): array
{
if (empty($data['user_id'])) {
$data['user_id'] = auth()->id();
}

return $data;
}
to the CreateIssue.php I added the if empty in hopes that it would only set the user if not given from the form. It appears that it does create the issue without problem AND that it sets the user_id so that part looks good. The issue is that sometime after the model actually saves and the 'save' succeeding from the perspective of the frontend, I get this:
Not null violation: 7 ERROR: null value in column "user_id" of relation "issues" violates not-null constraint DETAIL: Failing row contains (8, 2186f6af-4a49-48b3-b2fd-6a8b5e8ed730, null, First Issue, <p>Test3</p>, medium, null, 2023-08-02 10:09:38, 2023-08-02 10:09:38).
update "issues" SET "user_id" = ?, "updated_at" = 2023-08-02 10:09:38 WHERE "id" = 8
Not null violation: 7 ERROR: null value in column "user_id" of relation "issues" violates not-null constraint DETAIL: Failing row contains (8, 2186f6af-4a49-48b3-b2fd-6a8b5e8ed730, null, First Issue, <p>Test3</p>, medium, null, 2023-08-02 10:09:38, 2023-08-02 10:09:38).
update "issues" SET "user_id" = ?, "updated_at" = 2023-08-02 10:09:38 WHERE "id" = 8
I'm not sure why it would be trying to update the record that it just saved other than perhaps trying to set the updated_at time? But in that case, why is the user_id null? Perhaps it has old (submitted) data for the issue (before the mutate call)?
4 replies