manojhl
manojhl
FFilament
Created by manojhl on 6/9/2024 in #❓┊help
Troubleshooting $search variable accessibility in Select Field modifyQueryUsing() method
According to the document, the $search variable should be accessible within https://filamentphp.com/docs/3.x/forms/fields/select#customizing-the-relationship-query
Customizing the relationship query You may customize the database query that retrieves options using the third parameter of the relationship() method:
use Filament\Forms\Components\Select;
use Illuminate\Database\Eloquent\Builder;

Select::make('author_id')
->relationship(
name: 'author',
titleAttribute: 'name',
modifyQueryUsing: fn (Builder $query) => $query->withTrashed(),
)
use Filament\Forms\Components\Select;
use Illuminate\Database\Eloquent\Builder;

Select::make('author_id')
->relationship(
name: 'author',
titleAttribute: 'name',
modifyQueryUsing: fn (Builder $query) => $query->withTrashed(),
)
If you would like to access the current search query in the modifyQueryUsing function, you can inject $search.
I tried adding $search in the modifyQueryUsing but i got an error
Select::make('skills')
->multiple()
->relationship(
titleAttribute: 'name',
modifyQueryUsing: function (Builder $query, ?string $search) {
return $query->withTrashed()
->where('name', 'LIKE', '%' . $search . '%')
->orderByRaw(
"CASE
WHEN name LIKE ? THEN 1
WHEN name LIKE ? THEN 2
ELSE 3
END, name ASC",
[$search . '%', '%' . $search . '%']
)
->limit(20);
}
)
Select::make('skills')
->multiple()
->relationship(
titleAttribute: 'name',
modifyQueryUsing: function (Builder $query, ?string $search) {
return $query->withTrashed()
->where('name', 'LIKE', '%' . $search . '%')
->orderByRaw(
"CASE
WHEN name LIKE ? THEN 1
WHEN name LIKE ? THEN 2
ELSE 3
END, name ASC",
[$search . '%', '%' . $search . '%']
)
->limit(20);
}
)
An attempt was made to evaluate a closure for [Filament\Forms\Components\Select], but [$search] was unresolvable.
$search parameter should be accessible inside the modifyQueryUsing() method, right? am i missing something or is this a bug?
2 replies
FFilament
Created by manojhl on 5/31/2024 in #❓┊help
Custom model attributes in model
I wanted to get full_name from model user which is an custom attribute and not database column, Anyone has ideas on how to get full_name attributes as the title?
SelectFilter::make('user')
->relationship(
'user',
'first_name',
fn ($query) => $query->whereHas('requestFeatures')
)->searchable()->preload()
SelectFilter::make('user')
->relationship(
'user',
'first_name',
fn ($query) => $query->whereHas('requestFeatures')
)->searchable()->preload()
1 replies
FFilament
Created by manojhl on 5/28/2024 in #❓┊help
Is there a method to disable select row (checkbox) and display just the table with actions, filters
Currently i'm hiding the checkbox prefixed with each row with css but is there an offical way to remove this checkboxes from table table row. Something i can configure in table method in a resource?
4 replies
FFilament
Created by manojhl on 4/19/2024 in #❓┊help
How to have HTML content inside tooltip
I have requirement to have a html table with a tooltip when you hover over a table column cell, i have tried everything possible to make it work. need some advice on this
Tables\Columns\TextColumn::make('avg_usd')
->label('Avg Salary')
->tooltip(function (Model $record) {
$html = "<strong>Custom Tooltip</strong><br>";
$html .= "This is a custom tooltip for the average salary.";
return new HtmlString($html);
})
// ->tooltip(fn (Model $salary) => '<pre>' . print_r($salary->kuubiik_calc, true) . '</pre>')
->description(fn (Model $salary) => "KC: $" . (is_array($salary->kuubiik_calc) ? $salary->kuubiik_calc['total'] : ''))
->money('USD'),
Tables\Columns\TextColumn::make('avg_usd')
->label('Avg Salary')
->tooltip(function (Model $record) {
$html = "<strong>Custom Tooltip</strong><br>";
$html .= "This is a custom tooltip for the average salary.";
return new HtmlString($html);
})
// ->tooltip(fn (Model $salary) => '<pre>' . print_r($salary->kuubiik_calc, true) . '</pre>')
->description(fn (Model $salary) => "KC: $" . (is_array($salary->kuubiik_calc) ? $salary->kuubiik_calc['total'] : ''))
->money('USD'),
4 replies
FFilament
Created by manojhl on 3/26/2024 in #❓┊help
Filter null values using SelectFilter
I have a nullable column level with values [1,2,3,4,5], Currently I can filter by these value But How do i filter null values? to get records without any level
2 replies
FFilament
Created by manojhl on 3/24/2024 in #❓┊help
How to exclude a Model's attribute(object) to be passed to filament livewire component by default
I'm trying to build a admin interface for https://github.com/spatie/laravel-uptime-monitor and i got the error
Property type not supported in Livewire for property: [{}]
Property type not supported in Livewire for property: [{}]
I presume this is due to the package has these function in the Monitor model converting url attribute to Url object.
protected $appends = ['raw_url'];

public function getUrlAttribute(): ?Url
{
if (! isset($this->attributes['url'])) {
return null;
}

return Url::fromString($this->attributes['url']);
}

public function getRawUrlAttribute(): string
{
return (string) $this->url;
}
protected $appends = ['raw_url'];

public function getUrlAttribute(): ?Url
{
if (! isset($this->attributes['url'])) {
return null;
}

return Url::fromString($this->attributes['url']);
}

public function getRawUrlAttribute(): string
{
return (string) $this->url;
}
But i've no idea how to ignore this or deal with this in filamentphp and need some assistance. Thank you
1 replies