403gtfo
403gtfo
FFilament
Created by 403gtfo on 10/28/2024 in #❓┊help
Is sortable() and/or searchable() possible on a HasOneThrough relation?
I don't think I have asked this before... But it is a hard one. The setup: - One Staff can have many positions. - One Position has one Discipline. - Positions have an end_date field The question: Is it possible to have a HasOneThrough relation work with sortable() on the StaffResource? Relation:
public function latestDiscipline(): HasOneThrough
{ {
return $this->hasOneThrough(Discipline::class, Position::class, 'staff_id', 'id', 'id', 'discipline_id')
->where('is_active', true)
->orderBy('end_date', 'desc');
}
}

public function getLatestDisciplineNameAttribute()
{
$latestDiscipline = $this->latestDiscipline()->first();
return $latestDiscipline ? $latestDiscipline->name : null;
}
public function latestDiscipline(): HasOneThrough
{ {
return $this->hasOneThrough(Discipline::class, Position::class, 'staff_id', 'id', 'id', 'discipline_id')
->where('is_active', true)
->orderBy('end_date', 'desc');
}
}

public function getLatestDisciplineNameAttribute()
{
$latestDiscipline = $this->latestDiscipline()->first();
return $latestDiscipline ? $latestDiscipline->name : null;
}
Text column:
TextColumn::make('latest_discipline_name')
->label('Discipline')
// ->searchable()
->sortable()
->toggleable(),
TextColumn::make('latest_discipline_name')
->label('Discipline')
// ->searchable()
->sortable()
->toggleable(),
1 replies
FFilament
Created by 403gtfo on 9/26/2024 in #❓┊help
Sort one to many TextColumn based on formatted state?
Hey team, I am having another moment... is there a way to sort a one to many text column based on the concatenated string? Column:
TextColumn::make('citizenships.name')
->searchable()
->formatStateUsing(
fn($record) => $record->citizenships->map(fn($citizenship) => $citizenship->name)->join(', ')
)
->sortable(),
TextColumn::make('citizenships.name')
->searchable()
->formatStateUsing(
fn($record) => $record->citizenships->map(fn($citizenship) => $citizenship->name)->join(', ')
)
->sortable(),
Throws this error, as one would expect if it was using the column raw data to sort.
SQLSTATE[21000]: Cardinality violation: 1242 Subquery returns more than 1 row
SQLSTATE[21000]: Cardinality violation: 1242 Subquery returns more than 1 row
Any advice is greatly appreciated.
9 replies
FFilament
Created by 403gtfo on 9/12/2024 in #❓┊help
Is there an easy way to group dashboard widgets into tabs?
Hey team, just wondering if there is an easy way to group widgets into tabs on the default dashboard? Or is it more a 'go set up your own'? Example:
Tab1 name="Overview":
Widget 1,
Widget 2,
Tab2 name="Stats":
Widget 3,
Widget 4,
Tab1 name="Overview":
Widget 1,
Widget 2,
Tab2 name="Stats":
Widget 3,
Widget 4,
3 replies
FFilament
Created by 403gtfo on 9/9/2024 in #❓┊help
Help with persistent table order after saving
Hi team I have an edit page that redirect back to the table after using:
protected function getRedirectUrl(): string
{
return $this->getResource()::getUrl('index');
}
protected function getRedirectUrl(): string
{
return $this->getResource()::getUrl('index');
}
The problem is: If a user has changed the sorting, it resets and they have to resort again which can be a pain if they are doing a lot of updates. I also have this on the $table though that doesn't seem to store the order.
return $table
->persistFiltersInSession()
return $table
->persistFiltersInSession()
Any advice would be greatly appreciated. I am sure it is something simple.
5 replies
FFilament
Created by 403gtfo on 6/25/2024 in #❓┊help
Advanced Tables (Plugin) Example / advice.
I thought it might be best for me to put this in the help section and not just the community tab. is there a github repo showing some examples like for the demo? I've tried setting up filters on a table and all I want to do is say "For the Discipline filter, use the relation and a SELECT box". Clearly I am doing something wrong as it seems to preload this filter in when I hit reset. I only what the filter to appear when the user selects it. I am sure it is dead easy but I just missed it.
->filters([
AdvancedFilter::make()
->filterPickerSearch()
->filterPickerMaxHeight('240px')
->includeColumns()
->filters([
SelectFilter::make('discipline.name')
->relationship('discipline', 'name')
->multiple()
->preload(),
])
//
,
])
->filters([
AdvancedFilter::make()
->filterPickerSearch()
->filterPickerMaxHeight('240px')
->includeColumns()
->filters([
SelectFilter::make('discipline.name')
->relationship('discipline', 'name')
->multiple()
->preload(),
])
//
,
])
5 replies
FFilament
Created by 403gtfo on 5/13/2024 in #❓┊help
Noob question: Sorting a hasMany column in table
I'm really struggle sorry and I am sure it is dead easy to do. Apologies, I know I've asked a bunch of relation questions, but that seems to be where stuff explodes for me. What I am trying to do: I need the HIndex column in the Activities table to be sortable based on the related HIndex with the highest year value (or based on the formatted state would be even better) Model Activity: - has many HIndex via
public function hIndices()
{
return $this->hasMany(HIndex::class)->orderBy('year', 'desc');
}
public function hIndices()
{
return $this->hasMany(HIndex::class)->orderBy('year', 'desc');
}
Model HIndex : - Belongs to one Activity - Has the columns -- year -- value -- activity_id In the Activity resource I have:
TextColumn::make('hIndices.value')
->formatStateUsing(function ($record) {
// ... some stuff dont worry about it
}
->sortable(),
TextColumn::make('hIndices.value')
->formatStateUsing(function ($record) {
// ... some stuff dont worry about it
}
->sortable(),
But it throws: SQLSTATE[21000]: Cardinality violation: 1242 Subquery returns more than 1 row
3 replies
FFilament
Created by 403gtfo on 4/22/2024 in #❓┊help
is there a formatStateUsing for IconColumn?
What I have: I have a table with a one-to-many boolean icon column (positionData.is_active) Currently the State is populates with all the records for example (true, false, true) What I want to do: I just want a single value returned. What I have tried If it was a TextColumn I could use something like
TextColumn::make('positionData.is_active)
->formatStateUsing(
function ($record) {
$isActive = $record->positionData->sortByDesc('year')->values()->first()->is_active;
// render stuff here ...
}
TextColumn::make('positionData.is_active)
->formatStateUsing(
function ($record) {
$isActive = $record->positionData->sortByDesc('year')->values()->first()->is_active;
// render stuff here ...
}
But this doesnt seem to be a thing for IconColumns. I've tried using the
TextColumn::make('positionData.is_active)->icon(...)
TextColumn::make('positionData.is_active)->icon(...)
But the format and size is totally different than the Icon Columns. Any suggestions?
9 replies
FFilament
Created by 403gtfo on 2/12/2024 in #❓┊help
Global search box in filters draw.
Hey team, anyone know of a nice way to include a global search box in the filters panel on a table? I could manually write one but was wonding if anyone has a nice neat way of doing it?
2 replies
FFilament
Created by 403gtfo on 1/10/2024 in #❓┊help
3.1 Importer File type error
No description
19 replies
FFilament
Created by 403gtfo on 11/17/2023 in #❓┊help
getEloquentQuery() many to may relation multi row per attachment
I am trying to customize the query using getEloquentQuery() and am having trouble getting the query to return what I am after. Any help would be greatly appreciated, also if there is a better way please let me know. It may be more a eloquent help request than anything.
Setup: - Activity 1, Staff A, Staff B - Activity 2, Staff B What I need the query to return for me table: - Activity 1 Staff A - Activity 1 Staff B -Activity 2 Staff B There is a bunch of other joins and stuff I need to do based on the staff member thus I am try to use getEloquentQuery(). For the life of me I cant wrap my head around how I need to format it to make it work.
4 replies
FFilament
Created by 403gtfo on 11/7/2023 in #❓┊help
Help with creating a github bug ticket.
Sorry guys, I dont normally make bug tickets. I have tried making one twice now and the gitbot keeps closing it down claiming there is not repo provided... The first one that was true, but I couldn't seem to reopen it after updating it. The second one, just auto closed even when provided. It's not a big issue, and I could put in a hacky fix for myself, but I am just trying to assist in improvements. Any advice on how I was meant to format it or how I go about consensually stepping on the gitbot? Ticket: https://github.com/filamentphp/filament/issues/9517
9 replies