CGM
CGM
FFilament
Created by CGM on 10/2/2024 in #❓┊help
How to translate login page
I see there is a language file at vendor/filament/filament/resources/lang/en/pages/auth/login.php Where/how exactly do I bring this into my own project's lang/ directory to override things? I've attempted: lang/vendor/filament/filament/resources/lang/en/pages/auth/login.php lang/vendor/filament/en/login.php lang/en/login.php without any luck.
6 replies
FFilament
Created by CGM on 9/30/2024 in #❓┊help
How to add blade directive to filament head
I'm currently installing https://github.com/silviolleite/laravel-pwa into my filament app, and I'm at the step where I need to include the blade directive @laravelPWA into the <head> of my page. Here is where I need the directive to go:
<html>
<head>
<title>My Title</title>
...
@laravelPWA
</head>
<body>
...
My content
...
</body>
</html>
<html>
<head>
<title>My Title</title>
...
@laravelPWA
</head>
<body>
...
My content
...
</body>
</html>
How do I get to the Filament header template, or how do I add that directive to the header of the filament template?
5 replies
FFilament
Created by CGM on 9/25/2024 in #❓┊help
Using alpine to update a Form Field using an x-on event listener.
I feel like I'm missing something simple. If I have two form fields and want to use alpine to update another field 'on change', how can I do this? I want the interaction to be instant, without the roundtrip form the server (or at least to happen at the same time so it feels instant). Clearly I cannot x-model here as it doesn't work or I'm setting the value incorrectly.
Select::make('employee_selector')
->label('Select an employee')
->options($employees = $this->location()?->currentEmployees()->pluck('name', 'id')->toArray() ?: [])
->extraAttributes([
'x-data' => '{ selectedId: null }',
'x-model' => 'selectedId',
'x-on:new-employee-id.window' => 'selectedId = $event.detail.newId; console.log("updated to " + $event.detail.newId);',
]),
Select::make('employee_selector')
->label('Select an employee')
->options($employees = $this->location()?->currentEmployees()->pluck('name', 'id')->toArray() ?: [])
->extraAttributes([
'x-data' => '{ selectedId: null }',
'x-model' => 'selectedId',
'x-on:new-employee-id.window' => 'selectedId = $event.detail.newId; console.log("updated to " + $event.detail.newId);',
]),
The event is firing properly, I can see my console logs fill properly:
$dispatch('new-employee-id', { newId: state })
$dispatch('new-employee-id', { newId: state })
I think it is just where I'm trying to set the value is incorrect and where I need some pointers please. 🙂 selectedId = $event.detail.newId;
3 replies
FFilament
Created by CGM on 9/16/2024 in #❓┊help
How to add NPM added assets to Filament.
I'm getting a little lost in the docs on this one. I'm looking to integrate https://swiperjs.com/ into a project and want to include the sources (js/css) in my project using NPM. $ npm install swiper Could anyone point me in the right direction as to what to do next to ensure the proper imports happen when the field is loaded? How do I access the assets added using NPM in my field and then how/where do I import?
// import Swiper bundle with all modules installed
import Swiper from 'swiper/bundle';

// import styles bundle
import 'swiper/css/bundle';
// import Swiper bundle with all modules installed
import Swiper from 'swiper/bundle';

// import styles bundle
import 'swiper/css/bundle';
8 replies
FFilament
Created by CGM on 9/13/2024 in #❓┊help
SpatieMediaLibraryFileUpload - Display is very slow
I'm allowing users to upload images. However, I want to keep a high quality version for future cropping. How can I display a conversion (ie., thumbnail) in the field, but allow cropping of the original in the editor? The reason this is important is that some users have images that are 10+mb and the editor is taking for ever to load on mobile. I don't need the full image unless the editor is actively open.
SpatieMediaLibraryFileUpload::make('user_photo')
->collection('user_photos')
->disk('tenant_photos')
->maxSize(12288)
->visibility('public')
->image()
->imageEditor()
->imageCropAspectRatio('2:3'),
SpatieMediaLibraryFileUpload::make('user_photo')
->collection('user_photos')
->disk('tenant_photos')
->maxSize(12288)
->visibility('public')
->image()
->imageEditor()
->imageCropAspectRatio('2:3'),
when I add ->conversion('thumb') the editor/cropper modifies the thumbnail instead of the original, obliterating the image quality.
2 replies
FFilament
Created by CGM on 8/29/2024 in #❓┊help
How do I create a test for filtersForm() on dashboard?
I'm having a difficult time creating a test to ensure one of my filters is providing the correct select list in the filtersForm() method on my dashboard. How can I target this method?
class Dashboard extends \Filament\Pages\Dashboard
{
use HasFiltersForm;

public function filtersForm(Form $form): Form
{
return $form
->schema([
// These are the form fields I want to test...
// I just want to make sure a select list has the proper values.
]);
}
}
class Dashboard extends \Filament\Pages\Dashboard
{
use HasFiltersForm;

public function filtersForm(Form $form): Form
{
return $form
->schema([
// These are the form fields I want to test...
// I just want to make sure a select list has the proper values.
]);
}
}
3 replies
FFilament
Created by CGM on 7/23/2024 in #❓┊help
How do I change, or remove the Logo from the Login page?
No description
11 replies
FFilament
Created by CGM on 7/15/2024 in #❓┊help
Is there a unified place for mutateFormDataBeforeCreate() and mutateFormDataBeforeSave()?
I have some logic that I would like to run on both save and create for a specific field when it is being saved. Is there a unified place, for example in the resource class that runs on both new saves and on edit saves to keep code a bit cleaner?
13 replies
FFilament
Created by CGM on 7/11/2024 in #❓┊help
Hook for FileUpload field when file removed? (X Clicked to remove)
I have the following field:
FileUpload::make('logo')
->disk('tenant_logos')
->afterStateUpdated(function ($state) {
// Do stuff here...
})
->maxSize(12288)
->visibility('public')
->image()
->imageEditor(),
FileUpload::make('logo')
->disk('tenant_logos')
->afterStateUpdated(function ($state) {
// Do stuff here...
})
->maxSize(12288)
->visibility('public')
->image()
->imageEditor(),
It works when expected when uploading an image as ->afterStateUpdated() is fired, however when I click the (X) to remove the photo the ->afterStateUpdated() does not fire. Is there something I'm missing, or is there another hook I can use to run code when the image/upload is removed?
18 replies
FFilament
Created by CGM on 7/10/2024 in #❓┊help
In a test, should fillForm() be firing afterStateUpdated()?
I have the following field:
ColorPicker::make('primary_color')
->live()
->afterStateUpdated(function ($state) {
$this->dispatch('applyThemeColors', [
'primary_color' => $state,
]);
})
->hex()
->hexColor()
->nullable()
->helperText('Leave blank to use default colors'),
ColorPicker::make('primary_color')
->live()
->afterStateUpdated(function ($state) {
$this->dispatch('applyThemeColors', [
'primary_color' => $state,
]);
})
->hex()
->hexColor()
->nullable()
->helperText('Leave blank to use default colors'),
and the following test:
$component = livewire(BrandingSettings::class, ['location' => null])
->assertSuccessful()
->fillForm(['primary_color' => '#007bff'])
->assertDispatched('applyThemeColors');
$component = livewire(BrandingSettings::class, ['location' => null])
->assertSuccessful()
->fillForm(['primary_color' => '#007bff'])
->assertDispatched('applyThemeColors');
On the live site it all works, I assumed this test would have picked it up, however it doesn't. I'm just wondering is there something I need to do in my test to ensure the afterStateUpdated() is fired? The field is set to live().
12 replies
FFilament
Created by CGM on 7/2/2024 in #❓┊help
Adding 'confirmation modal' to a checkbox?
I feel like I'm missing something simple in the docs in regards to action modals. Is there a way to add a 'are you sure you want to toggle this checkbox' style of modal to a checkbox field? Something that would pop up with a confirmation before ->updateStateUsing() is called? I'm using a table builder checkbox colum
11 replies
FFilament
Created by CGM on 6/27/2024 in #❓┊help
Prefill Resource Create Fields from beforeFill()?
I'm looking to prefill some resource fields (when Creating a resource) using values from a cookie. Is the beforeFill() Life Cycle hook an appropriate place to do this? If so, how do I actually interact with the $form from inside this hook? Is there another more appropriate place to do this?
9 replies
FFilament
Created by CGM on 6/25/2024 in #❓┊help
Where to put custom logic shared across multiple Resource classes
Just looking for some guidance on where might be the most appropriate place to put logic that I'm looking to share across multiple Resource classes. My auth logic for some of the action buttons (to hide/show them) is getting a little long and I don't like having the same code in 8 different places. Where might be the best place to put this custom logic? Is there a 'filament way' or am I better off creating a new trait?
4 replies
FFilament
Created by CGM on 6/24/2024 in #❓┊help
How do I test MorphToSelect fields in forms?
I'm trying to write a test to ensure my MorphToSelect field is ->required(), but it is not behaving as I would expect. Are you all aware of any examples of testing the MorphToSelect field in custom forms, or even in panel forms? Here is the field for reference: Here is the example field for reference:
MorphToSelect::make('followup')
->required()
->types([
MorphToSelect\Type::make(CustomMessage::class)
->getOptionLabelFromRecordUsing(fn (CustomMessage $record): string => "{$record->name}")
->titleAttribute('name'),
MorphToSelect\Type::make(Redirect::class)
->getOptionLabelFromRecordUsing(fn (Redirect $record): string => "{$record->name}")
->titleAttribute('name'),
])
MorphToSelect::make('followup')
->required()
->types([
MorphToSelect\Type::make(CustomMessage::class)
->getOptionLabelFromRecordUsing(fn (CustomMessage $record): string => "{$record->name}")
->titleAttribute('name'),
MorphToSelect\Type::make(Redirect::class)
->getOptionLabelFromRecordUsing(fn (Redirect $record): string => "{$record->name}")
->titleAttribute('name'),
])
3 replies
FFilament
Created by CGM on 6/24/2024 in #❓┊help
Testing select list values
Is there a way, other than looking for strings in HTML, to test if a specific value is visible or not visible in a form fields select list?
4 replies
FFilament
Created by CGM on 6/21/2024 in #❓┊help
Changing the MorphToSelect Placeholder
Is there a way to change the MorphToSelect placeholder? I get this error when using ->placeholder() Method Filament\Forms\Components\MorphToSelect::placeholder does not exist. I'm looking to change the text that reads "Select an option" for the initial 'type' selection.
2 replies
FFilament
Created by CGM on 6/19/2024 in #❓┊help
How can I use @error blade directives in my custom form field blade files?
I know it's me missing something obvious, but I'm struggling to properly use @error() @enderror in my custom fields blade file. What goes inside of @error(<here>)? I attempted source diving and found $errors->has($statePath) but this gives me an error: array_key_exists(): Argument #1 ($key) must be a valid array offset type when I try to use it in my own blade template. This is a field created using artisan make:form-field, so nothing too special I don't think.
3 replies
FFilament
Created by CGM on 5/27/2024 in #❓┊help
How to test pages that extend extend ManageRelatedRecords (Create via Modal)
How would you properly setup a simple test for a custom page that extends ManageRelatedRecords? This is a standard page create using make:filament-page and selecting Relationship. The form is in a Modal and I think that is where I'm getting stuck. I would love to see an example of how to just see how to assert the successful submission of a create form (no errors) via the modal. I think I could plow through the rest from there. 🙂
8 replies
FFilament
Created by CGM on 5/17/2024 in #❓┊help
How do I pass values through a render hook?
I have the following hook for my EditUser::class
->renderHook(
PanelsRenderHook::CONTENT_END,
fn (): View => view('components.tenant.roles.role-editor'),
[EditUser::class],
)
->renderHook(
PanelsRenderHook::CONTENT_END,
fn (): View => view('components.tenant.roles.role-editor'),
[EditUser::class],
)
but the view takes a prop of @props(['userId']) how do I get this from my EditUser::class and into the view?
7 replies
FFilament
Created by CGM on 5/17/2024 in #❓┊help
Adding Livewire Component to Sidebar
If I wanted to add a custom livewire component to the sidebar, above or below the standard navigation, where would I start that journey? Is there a nav hook, or a template I can override?
8 replies