Bruno Silva
Bruno Silva
FFilament
Created by Bruno Silva on 11/21/2024 in #❓┊help
Using Spatie/Laravel-Data to validate Filament Forms
Is it possible to take advantage of Spatie/Laravel-Data to validate Filament forms? Looking to integrate both for consistent validation across API, commands, jobs, and Filament forms. Current approach:
$rules = StockMovementData::getValidationRules([]);
return [
TextInput::make('quantity')
->rules($rules['quantity'])
->numeric()
];
$rules = StockMovementData::getValidationRules([]);
return [
TextInput::make('quantity')
->rules($rules['quantity'])
->numeric()
];
While this works for basic rules, it doesn't handle: - Complex validations requiring context (ValidationContext) - Custom messages - Type casting - Data Object reusability Has anyone successfully integrated these tools? Looking for examples or best practices.
5 replies
FFilament
Created by Bruno Silva on 11/19/2024 in #❓┊help
Disable all browser validation
Is there a way to disable ALL browser validation from all form fields? like a global setting? Not only required, but minValue, maxValue... all possible validation errors
2 replies
FFilament
Created by Bruno Silva on 10/14/2024 in #❓┊help
Unable to hide childItems in custom NavigationItem
I'm making a custom navigation setup and I want to conditionally hide an item from the childItems([...]), but it does not seem to work... this is a simple code to debug it faster, "nav-item-5" should be hidden
->navigation(function (NavigationBuilder $builder): NavigationBuilder {
return $builder
->items([
NavigationItem::make('nav-item-1')
->url('#'),
])
->groups([
NavigationGroup::make('group-1')
->items([
NavigationItem::make('nav-item-2')
->icon('heroicon-o-banknotes')
->url('#'),
NavigationItem::make('nav-item-3')
->icon('heroicon-o-banknotes')
->url('#')
->isActiveWhen(fn () => true)
->childItems([
NavigationItem::make('nav-item-4')
->url('#'),
NavigationItem::make('nav-item-5')
->hidden()
->url('#'),
]),
]),
]);
})
->navigation(function (NavigationBuilder $builder): NavigationBuilder {
return $builder
->items([
NavigationItem::make('nav-item-1')
->url('#'),
])
->groups([
NavigationGroup::make('group-1')
->items([
NavigationItem::make('nav-item-2')
->icon('heroicon-o-banknotes')
->url('#'),
NavigationItem::make('nav-item-3')
->icon('heroicon-o-banknotes')
->url('#')
->isActiveWhen(fn () => true)
->childItems([
NavigationItem::make('nav-item-4')
->url('#'),
NavigationItem::make('nav-item-5')
->hidden()
->url('#'),
]),
]),
]);
})
4 replies
FFilament
Created by Bruno Silva on 9/26/2024 in #❓┊help
conditionally set dark mode
is it possible to set dark mode based on certain config? I want to disable the theme mode switcher and set the dark mode based on a setting from laravel settings, but I can't figure out how to do it (as the darkMode method do not accept closure)
6 replies
FFilament
Created by Bruno Silva on 8/1/2024 in #❓┊help
Require Login/Register to Execute Action
I have a public page (Livewire component) with a Filament form:
class CreateFirstBooking extends SimplePage implements HasForms
{
use InteractsWithForms;

public ?array $data = [];

// ...

public function form(Form $form): Form
{
// public form...
}

// ...

public function submit()
{
// exec code after the user logs in or registers
}
}
class CreateFirstBooking extends SimplePage implements HasForms
{
use InteractsWithForms;

public ?array $data = [];

// ...

public function form(Form $form): Form
{
// public form...
}

// ...

public function submit()
{
// exec code after the user logs in or registers
}
}
I wish to submit this form and execute some code after the user logs in or registers... The flow would be: - Fill out the form - Click the submit button - Register or Login - Use that user recently created or logged user to execute some code Is that possible using the Filament login/register form?
9 replies
FFilament
Created by Bruno Silva on 7/30/2024 in #❓┊help
Checkboxlist selecting all options
I have a simple CheckboxList, but when I click in one option, it selects or deselects all of them. The only difference of that checkboxlist is that it is in a resource from another panel (my "client" panel, which is not the default "admin" one) * other fields in the same form works as they should.
CheckboxList::make('technologies')
->options([
'tailwind' => 'Tailwind CSS',
'alpine' => 'Alpine.js',
'laravel' => 'Laravel',
'livewire' => 'Laravel Livewire',
])
CheckboxList::make('technologies')
->options([
'tailwind' => 'Tailwind CSS',
'alpine' => 'Alpine.js',
'laravel' => 'Laravel',
'livewire' => 'Laravel Livewire',
])
7 replies
FFilament
Created by Bruno Silva on 7/15/2024 in #❓┊help
livewire()->fillForm() not working
I have several tests using the same helper. All tests are working except for one, and I can't figure out why. I'm going to leave the simplest example possible just to show the problem: VehicleTest:
it('works', function () {
livewire(CreateVehicle::class)
->fillForm([
'plate' => 'someplate',
])
->assertFormSet([
'plate' => 'someplate',
]);
});
it('works', function () {
livewire(CreateVehicle::class)
->fillForm([
'plate' => 'someplate',
])
->assertFormSet([
'plate' => 'someplate',
]);
});
VehicleResource:
public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('plate'),
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('plate'),
]);
}
CreateVehicle:
class CreateVehicle extends CreateRecord
{
protected static string $resource = VehicleResource::class;
}
class CreateVehicle extends CreateRecord
{
protected static string $resource = VehicleResource::class;
}
That exact test is not working, giving: Failed asserting that null matches expected 'someplate' Even though it works if I manually create that vehicle in the actual page.
9 replies
FFilament
Created by Bruno Silva on 7/8/2024 in #❓┊help
App Dropdowns full width
All dropdowns of the app are "full width", actually they are with a strange positioning. I've tried filament:upgrade, npm run dev, npm run build, remove node_modules... nothing worked. I do not have a custom theme or any custom css I have this bit of code in the AdminPanelProvider, to handle the hot reload:
public function register(): void
{
parent::register();
FilamentView::registerRenderHook('panels::body.end', function (): string {
return Blade::render('@vite("resources/js/app.js")');
});
}
public function register(): void
{
parent::register();
FilamentView::registerRenderHook('panels::body.end', function (): string {
return Blade::render('@vite("resources/js/app.js")');
});
}
5 replies
FFilament
Created by Bruno Silva on 5/24/2024 in #❓┊help
Repeater with MorphTo relationship don't work on create page
I have a polymorphic model "Content", and the possible entities "ContentVideo" and "ContentQuiz" for example. in the "ContentResource" I have this form with a repeater, relating to the models "QuizQuestion" and "QuizOption".
Group::make()
->relationship('entity')
->schema([
Repeater::make('questions')
->relationship()
->schema([
Textarea::make('question'),
Repeater::make('options')
->relationship()
->schema([
TextInput::make('option'),
]),
]),
]),
Group::make()
->relationship('entity')
->schema([
Repeater::make('questions')
->relationship()
->schema([
Textarea::make('question'),
Repeater::make('options')
->relationship()
->schema([
TextInput::make('option'),
]),
]),
]),
so, "Content" morphsTo "ContentQuiz", "ContentQuiz" hasmany "questions", and "ContentQuestion" has many "options" This repeater works on the edit page, but not on the create page, I get the error:
Call to undefined method App\Models\Content::questions()
Call to undefined method App\Models\Content::questions()
If a add a ->model(ContentQuiz) in the Repeater chain, it works on the create page, but stops working in the edit page
1 replies
FFilament
Created by Bruno Silva on 4/14/2024 in #❓┊help
Create related record inside infolist
How can I create a record of another model inside a infolist using an action button? I have a infolist in my "BookingResource", I want that button to create a "Invoice" (Booking and Invoice are related), how can I do that? with a modal if possible. I'm trying to do something like this but it's not working:
Actions::make([
Action::make('createInvoice')
->icon('heroicon-o-currency-dollar')
->action(function (Booking $record) {
/* Invoice::factory()->create([
// ]) // don't thing this is the right aproach */
})
->form([
TextInput::make('total')
->label('Total')
->required(),
]),
])
Actions::make([
Action::make('createInvoice')
->icon('heroicon-o-currency-dollar')
->action(function (Booking $record) {
/* Invoice::factory()->create([
// ]) // don't thing this is the right aproach */
})
->form([
TextInput::make('total')
->label('Total')
->required(),
]),
])
The motive is that I need the booking to have a invoice featured before I can complete the booking, if there's a better a way to do this, let me know
7 replies
FFilament
Created by Bruno Silva on 3/30/2024 in #❓┊help
How to test Infolist Action?
I have a infolist with a ActionsGroup, I want to test if those buttons are working, but I can't figure out how to trigger those actions in the tests. (they work normally in the app) Infolist Action:
Action::make('cancelBooking')
->color('danger')
->requiresConfirmation()
->disabled(function (Booking $record) {
return $record->cancelled_at || $record->entered_at || $record->exited_at;
})
->action(function (Booking $record) {
$record->cancelled_at = now();
$record->save();

Notification::make()
->title('Booking cancelled')
->success()
->send();
}),
Action::make('cancelBooking')
->color('danger')
->requiresConfirmation()
->disabled(function (Booking $record) {
return $record->cancelled_at || $record->entered_at || $record->exited_at;
})
->action(function (Booking $record) {
$record->cancelled_at = now();
$record->save();

Notification::make()
->title('Booking cancelled')
->success()
->send();
}),
Test:
livewire(ViewBooking::class, ['record' => $booking->getRouteKey()])
->callInfolistAction('action', 'cancelBooking');

expect($booking->status)->toBe(BookingStatus::CANCELLED);
livewire(ViewBooking::class, ['record' => $booking->getRouteKey()])
->callInfolistAction('action', 'cancelBooking');

expect($booking->status)->toBe(BookingStatus::CANCELLED);
With that test I get:
Call to a member function getKey() on null
Call to a member function getKey() on null
The button does exists in the test because I "assertSee" it and it passes, but I cannot call it's action
21 replies
FFilament
Created by Bruno Silva on 3/5/2024 in #❓┊help
Count same relationship in multiple columns
I want to have some columns counting the same relationship, but with a few differences, such as different status. For example:
Tables\Columns\TextColumn::make('parking_spots_count')
->label('Total Parking Spots')
->counts('parkingSpots'),
Tables\Columns\TextColumn::make('parking_spots_available_count')
->label('Available Parking Spots')
->counts([
'parkingSpots' => fn (Builder $query) => $query->where('status', 'available'),
]),
Tables\Columns\TextColumn::make('parking_spots_count')
->label('Total Parking Spots')
->counts('parkingSpots'),
Tables\Columns\TextColumn::make('parking_spots_available_count')
->label('Available Parking Spots')
->counts([
'parkingSpots' => fn (Builder $query) => $query->where('status', 'available'),
]),
both of these columns work when used alone, but they don't work together (there's no error, they just don't show data). I tried using one of them as "sum" or changing the "make" name, but I could not make it work, I'm reading the docs but I can't find a best practice solution for that
2 replies
FFilament
Created by Bruno Silva on 3/3/2024 in #❓┊help
How can I test a form from a modal? (simple resource)
I have some resources made with --simple flag, so they don't have Create, Edit or View pages, only the Manage class. I would like to know 2 things, how to assert the modal rendering and how to test the form (because the fillForm seems to not work in this case). 1 - is this a good assertion for the "render modal test"?
livewire($manageModelClass)
->callAction('create')
->assertSeeHtml('fi-modal-window')
->assertSee('Create');
livewire($manageModelClass)
->callAction('create')
->assertSeeHtml('fi-modal-window')
->assertSee('Create');
2 - how to use the fillForm for modals?
livewire($manageModelClass)
->callAction('create') // it does render the modal
->assertFormExists() // error
->fillForm($formData) // error
livewire($manageModelClass)
->callAction('create') // it does render the modal
->assertFormExists() // error
->fillForm($formData) // error
9 replies
FFilament
Created by Bruno Silva on 2/28/2024 in #❓┊help
Handling Model Deletion with onDelete('restrict')
I set onDelete('restrict') in my model migration to prevent deleting records with active relationships. However, I still face an "Integrity constraint violation" error when attempting deletion. How can I handle this to stop the error and notify users that they can't delete records with active relationships?
5 replies
FFilament
Created by Bruno Silva on 1/27/2024 in #❓┊help
How to apply money mask to a input field
I have a money input field and I really want to format as BRL money 999.999,99 automatically as I type. I've given RawJS and alpine a shot, but I just can't seem to figure it out. Any ideas?
4 replies
FFilament
Created by Bruno Silva on 1/27/2024 in #❓┊help
Input field inside repeater don't work / get validated correctly
I have a simple "quantity" field inside a repeater, I tried to use: ->integer() ->gt(0) ->minValue(1) but those validations don't work, I can still set a number less than 0, even using the arrows (for the "minValue" method), and I don't get any errors on the submit (for the "integer" and "gt" validations). If I put that same input outside the repeater, it works...
1 replies