tuto1902
tuto1902
Explore posts from servers
FFilament
Created by tuto1902 on 4/20/2024 in #❓┊help
Testing custom table filters
I have a table with the following custom filter:
Tables\Filters\Filter::make('year')
->form([
Forms\Components\TextInput::make('yearFrom')
->label('From Year'),
Forms\Components\TextInput::make('yearTo')
->label('To Year')
])
->query(function (Builder $query, array $data) {
return $query
->when($data['yearFrom'], function (Builder $query, $yearFrom) {
$query->where('year', '>=', $yearFrom);
})
->when($data['yearTo'], function (Builder $query, $yearTo) {
$query->where('year', '<=', $yearTo);
});
})
Tables\Filters\Filter::make('year')
->form([
Forms\Components\TextInput::make('yearFrom')
->label('From Year'),
Forms\Components\TextInput::make('yearTo')
->label('To Year')
])
->query(function (Builder $query, array $data) {
return $query
->when($data['yearFrom'], function (Builder $query, $yearFrom) {
$query->where('year', '>=', $yearFrom);
})
->when($data['yearTo'], function (Builder $query, $yearTo) {
$query->where('year', '<=', $yearTo);
});
})
I'm trying to write a test case for this filter that looks like this:
it('can filter posts by a year from', function () {

$cars = Car::factory()->count(3)
->state(new Sequence(
['year' => 2016],
['year' => 2017],
['year' => 2018],
))
->for(Brand::factory())
->create();

$yearFrom = 2017;

Livewire::test(CarList::class)
->assertCanSeeTableRecords($cars)
->filterTable('year', $yearFrom )
->assertCanSeeTableRecords(
$cars->where('year', '>=', $yearFrom)
)
->assertCanNotSeeTableRecords(
$cars->where('year', '<', $yearFrom)
);
});
it('can filter posts by a year from', function () {

$cars = Car::factory()->count(3)
->state(new Sequence(
['year' => 2016],
['year' => 2017],
['year' => 2018],
))
->for(Brand::factory())
->create();

$yearFrom = 2017;

Livewire::test(CarList::class)
->assertCanSeeTableRecords($cars)
->filterTable('year', $yearFrom )
->assertCanSeeTableRecords(
$cars->where('year', '>=', $yearFrom)
)
->assertCanNotSeeTableRecords(
$cars->where('year', '<', $yearFrom)
);
});
My problem is that, when I run this test, the data coming into the ->query() method is empty
[
'yearFrom' => null
'yearTo' => null
]
[
'yearFrom' => null
'yearTo' => null
]
How can I set the values of a custom filter using ->filterTable()?
3 replies
FFilament
Created by tuto1902 on 1/24/2024 in #❓┊help
Conditionally change the background of a repeatable entry item
Is there an easy way of changing the background of an Infolist Repeatable Entry child item based on the record information
5 replies
FFilament
Created by tuto1902 on 9/30/2023 in #❓┊help
Breadcrumbs showing both left < and right > chevrons
No description
8 replies
FFilament
Created by tuto1902 on 9/20/2023 in #❓┊help
Simple repeater values not showing on edit
No description
33 replies
FFilament
Created by tuto1902 on 9/16/2023 in #❓┊help
Default Active Tab Not Working for Tab Filter
In my List page I have a Tabs filter for each day of the week. But when I try to set the default active tab, it just wont work. The default active tab is always the first one no matter what I return from getDefaultActiveTab()
public function getTabs(): array
{
return [
'Sunday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Sunday)),
'Monday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Monday)),
'Tuesday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Tuesday)),
'Wednesday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Wednesday)),
'Thursday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Thursday)),
'Friday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Friday)),
'Saturday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Saturday)),
];
}

public function getDefaultActiveTab(): string | int | null
{
return 'Tuesday';
}
public function getTabs(): array
{
return [
'Sunday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Sunday)),
'Monday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Monday)),
'Tuesday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Tuesday)),
'Wednesday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Wednesday)),
'Thursday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Thursday)),
'Friday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Friday)),
'Saturday' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('day_of_week', DaysOfTheWeek::Saturday)),
];
}

public function getDefaultActiveTab(): string | int | null
{
return 'Tuesday';
}
9 replies
FFilament
Created by tuto1902 on 9/4/2023 in #❓┊help
Multi Tenancy Doesn't work With Modal (--simple) Resources
I have multi-tenancy setup on my panel. All the relationships are properly set on both the tenant and the resource models. New resource records created via modals (simple resource) won't get assigned to the current tenant, where if I create the same resource but without the --simple option, it works fine. Is there a reason why simple resources don't play well with multi-tenancy?
2 replies
FFilament
Created by tuto1902 on 8/15/2023 in #❓┊help
Delete Tenant
I might know the answer already (No) but I might as well ask. Just to be sure. Is there a way, or is it even allowed to delete Tenants?
31 replies