AlexAnder
AlexAnder
FFilament
Created by AlexAnder on 6/14/2024 in #❓┊help
How to "disable globalScope" in "Listing records" when "Using tabs to filter the records"
use Filament\Resources\Components\Tab;
use Illuminate\Database\Eloquent\Builder;

public function getTabs(): array
{
return [
'all' => Tab::make(),
'childrens' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->whereHas('childrens'))
->withoutGlobalScopes(), // the global scope is belongsTo(auth()->user())
];
}
use Filament\Resources\Components\Tab;
use Illuminate\Database\Eloquent\Builder;

public function getTabs(): array
{
return [
'all' => Tab::make(),
'childrens' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->whereHas('childrens'))
->withoutGlobalScopes(), // the global scope is belongsTo(auth()->user())
];
}
"->withoutGlobalScopes()" doesn't work.
3 replies
FFilament
Created by AlexAnder on 5/27/2024 in #❓┊help
Why View Page needs viewAny policy role to be true for viewing?
Why View Page needs viewAny policy role to be true for viewing? Is it possible to override?
5 replies
FFilament
Created by AlexAnder on 4/18/2024 in #❓┊help
Custom page layout divide in 3 columns
I created custom page and want to split page content into 3 columns? I try all of tailwinds flex/grids, etc.., nothing works. Is there is some way to implement this?
17 replies
FFilament
Created by AlexAnder on 3/18/2024 in #❓┊help
Select or Create in attach modal freezes (no scroll)
When in RealitionManager choose attach and in select there is no wanted record, choose create witch opens new modal for create. Then It's creates, closes create modal, selects active record in select and you can attach. After modal closes, screen lost it's scroll. All actions works, but scroll returns after refresh the page.
2 replies
FFilament
Created by AlexAnder on 3/18/2024 in #❓┊help
Table Filters DatePicker native(false) error
When using DatePicker in Table Filters with native(false), in console returns error:
Alpine Expression Error: displayText is not defined
Expression: "displayText"
<input id="tableFilters.date.date_from" class="w-full border-none bg-tr…sm:text-sm sm:leading-6" readonly="" placeholder="" wire:key="uzFSJtiB92fiifV63GQ0.tab…DatePicker.display-text" x-model="displayText">
Alpine Expression Error: displayText is not defined
Expression: "displayText"
<input id="tableFilters.date.date_from" class="w-full border-none bg-tr…sm:text-sm sm:leading-6" readonly="" placeholder="" wire:key="uzFSJtiB92fiifV63GQ0.tab…DatePicker.display-text" x-model="displayText">
The code:
Filter::make('date')
->form([
DatePicker::make('date_from')
->label('Datums no')
->native(false)
->displayFormat('d.m.Y')
->closeOnDateSelection(true),
DatePicker::make('date_to')
->label('Datums līdz')
->native(false)
->displayFormat('d.m.Y')
->closeOnDateSelection(true),
])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['date_from'],
fn (Builder $query, $date): Builder => $query->whereDate('date', '>=', $date),
)
->when(
$data['date_to'],
fn (Builder $query, $date): Builder => $query->whereDate('date', '<=', $date),
);
})
->indicateUsing(function (array $data): array {
$indicators = [];
if ($data['date_from'] ?? null) {
$indicators['date_from'] = 'Datums no: '.Carbon::parse($data['date_from'])->format('d.m.Y');
}
if ($data['date_to'] ?? null) {
$indicators['date_to'] = 'Datums līdz: '.Carbon::parse($data['date_to'])->format('d.m.Y');
}

return $indicators;
}),
Filter::make('date')
->form([
DatePicker::make('date_from')
->label('Datums no')
->native(false)
->displayFormat('d.m.Y')
->closeOnDateSelection(true),
DatePicker::make('date_to')
->label('Datums līdz')
->native(false)
->displayFormat('d.m.Y')
->closeOnDateSelection(true),
])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['date_from'],
fn (Builder $query, $date): Builder => $query->whereDate('date', '>=', $date),
)
->when(
$data['date_to'],
fn (Builder $query, $date): Builder => $query->whereDate('date', '<=', $date),
);
})
->indicateUsing(function (array $data): array {
$indicators = [];
if ($data['date_from'] ?? null) {
$indicators['date_from'] = 'Datums no: '.Carbon::parse($data['date_from'])->format('d.m.Y');
}
if ($data['date_to'] ?? null) {
$indicators['date_to'] = 'Datums līdz: '.Carbon::parse($data['date_to'])->format('d.m.Y');
}

return $indicators;
}),
4 replies
FFilament
Created by AlexAnder on 2/1/2024 in #❓┊help
Long $recordTitleAttribute in breadcrumbs
I need to globaly search by $recordTitleAttribute, but on edit page in breadcrumbs this value is very long. How to make it shorter..
2 replies
FFilament
Created by AlexAnder on 1/19/2024 in #❓┊help
RelationManager table custom query by role Policy
It's possible to rewrite RelationManager table query to show only records, witch has allowed by role?
2 replies
FFilament
Created by AlexAnder on 12/7/2023 in #❓┊help
Forms\Components\Select with relationship loads all records from DB
My code
...
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('author_id')
->relationship('author', 'name')
...
...
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('author_id')
->relationship('author', 'name')
...
Post.php - Model
...

public function author(): BelongsTo
{
return $this
->belongsTo(User::class, 'author_id');
}

...
...

public function author(): BelongsTo
{
return $this
->belongsTo(User::class, 'author_id');
}

...
From DB selects all users. Its all table records.. (not enogth RAM) Also from people table is the same.. DB
SELECT "users"."name", "users"."id" FROM "users" ORDER BY "users"."name" ASC
SELECT "users"."name", "users"."id" FROM "users" ORDER BY "users"."name" ASC
And PHP crashed because off memory exhausted..
2 replies
FFilament
Created by AlexAnder on 11/10/2023 in #❓┊help
Keybindings works only once
If I edit resource directly, then "ctrl+s" works one time(first time) if in resource I have repeater with relationship and I choose the record, then "ctrl+s" doesn't works anymore.
2 replies
FFilament
Created by AlexAnder on 10/5/2023 in #❓┊help
Custom AttachAction
Can someone can help? I have peoples connected thru polymorphic relation MorphToMany. When I attach person to person, in db I get
[
'person_id' => 1,
'personable_id' => 2,
'personable_type' => 'App\Models\Person',
];
[
'person_id' => 1,
'personable_id' => 2,
'personable_type' => 'App\Models\Person',
];
The questions is: Ho to customize AttachAction to get records in db in both directions, so on both persons I get relation with each other?
7 replies
FFilament
Created by AlexAnder on 9/19/2023 in #❓┊help
Auto scrolling for navigation selected menu
On v2, there was renderHook for Auto scrolling for navigation selected menu. If there is the same for v3
12 replies
FFilament
Created by AlexAnder on 9/10/2023 in #❓┊help
FileUpload with ImageEditor on save prevent redirect
How to prevent redirect on save, if on resource there is FileUpload with ImageEditor and also
protected function getRedirectUrl(): string
{
return $this->previousUrl ?? $this->getResource()::getUrl('index');
}
protected function getRedirectUrl(): string
{
return $this->previousUrl ?? $this->getResource()::getUrl('index');
}
2 replies
FFilament
Created by AlexAnder on 8/31/2023 in #❓┊help
old web page tricks..
Hi, where is the old filament page tricks page? There was post about edit related model (from relationmanager) in edit page, instead of modal
6 replies
FFilament
Created by AlexAnder on 8/17/2023 in #❓┊help
Is it possible to realize something like this.
I have models with relationships and want to edit actual values, but input fields are not linked to model values. In SurveyResource edit:
Forms\Components\Section::make()
->schema(function ($record) {
$data = [];
foreach ($record->categories as $category) {
foreach ($category->answers as $answer) {
$data[] = Forms\Components\Group::make()
->schema([
Forms\Components\TextInput::make('answer'),
]);
}
}
return $data;
})
Forms\Components\Section::make()
->schema(function ($record) {
$data = [];
foreach ($record->categories as $category) {
foreach ($category->answers as $answer) {
$data[] = Forms\Components\Group::make()
->schema([
Forms\Components\TextInput::make('answer'),
]);
}
}
return $data;
})
I would appreciate the advice.
2 replies
FFilament
Created by AlexAnder on 8/2/2023 in #❓┊help
Rewrite Global search
Maybe someone will need a solution for rewrite global search. It's searches by different column (in my case PostgreSql full text search column - tsvector data type) I did it like this. Enable global search
protected static ?string $recordTitleAttribute = 'topic';
protected static ?string $recordTitleAttribute = 'topic';
Rewrite global search results (getGlobalSearchResults)
public static function getGlobalSearchResults(string $searchQuery): Collection
{
$customSearchQuery = Str::replace(' ', ':* & ', trim($searchQuery));

return RfiIncome::query()
->whereRaw("rfi_incomes_fts @@ to_tsquery('english', ?)", [$customSearchQuery.':*'])
->limit(static::getGlobalSearchResultsLimit())
->get()
->map(function (Model $record): ?GlobalSearchResult {
$url = static::getGlobalSearchResultUrl($record);

if (blank($url)) {
return null;
}

return new GlobalSearchResult(
title: static::getGlobalSearchResultTitle($record),
url: $url,
details: static::getGlobalSearchResultDetails($record),
actions: static::getGlobalSearchResultActions($record),
);
})
->filter();

}
public static function getGlobalSearchResults(string $searchQuery): Collection
{
$customSearchQuery = Str::replace(' ', ':* & ', trim($searchQuery));

return RfiIncome::query()
->whereRaw("rfi_incomes_fts @@ to_tsquery('english', ?)", [$customSearchQuery.':*'])
->limit(static::getGlobalSearchResultsLimit())
->get()
->map(function (Model $record): ?GlobalSearchResult {
$url = static::getGlobalSearchResultUrl($record);

if (blank($url)) {
return null;
}

return new GlobalSearchResult(
title: static::getGlobalSearchResultTitle($record),
url: $url,
details: static::getGlobalSearchResultDetails($record),
actions: static::getGlobalSearchResultActions($record),
);
})
->filter();

}
Maybe someone can give better solution..
1 replies
FFilament
Created by AlexAnder on 7/31/2023 in #❓┊help
max_content_width
Where to add max_content_width in v3
4 replies
FFilament
Created by AlexAnder on 7/26/2023 in #❓┊help
filament v3.0.0-alpha121
After installing (composer require filament/filament:"^3.0") on php artisan about I get v3.0.0-alpha121 If I change in composer.json to "^3.0@beta" then composer says:
filament/support[v3.0.0-beta1, ..., v3.0.0-beta12] require symfony/html-sanitizer ^6.1 -> satisfiable by symfony/html-sanitizer[v6.1.0-BETA1, ..., 6.4.x-dev].
league/uri[6.5.0, ..., 6.7.x-dev] require psr/http-message ^1.0 -> found psr/http-message[1.0, 1.0.1, 1.1] but it conflicts with your root composer.json require (^2.0).
filament/support[v3.0.0-beta1, ..., v3.0.0-beta12] require symfony/html-sanitizer ^6.1 -> satisfiable by symfony/html-sanitizer[v6.1.0-BETA1, ..., 6.4.x-dev].
league/uri[6.5.0, ..., 6.7.x-dev] require psr/http-message ^1.0 -> found psr/http-message[1.0, 1.0.1, 1.1] but it conflicts with your root composer.json require (^2.0).
and
league/uri[6.5.0, ..., 6.7.x-dev] require psr/http-message ^1.0 -> found psr/http-message[1.0, 1.0.1, 1.1] but it conflicts with your root composer.json require (^2.0).
league/uri[6.5.0, ..., 6.7.x-dev] require psr/http-message ^1.0 -> found psr/http-message[1.0, 1.0.1, 1.1] but it conflicts with your root composer.json require (^2.0).
On a fresh laravel install
10 replies
FFilament
Created by AlexAnder on 7/19/2023 in #❓┊help
Disable search in "globalSearch"
Hi. I am confuse. DB is PostgreSQL. I have in Resource
protected static ?string $recordTitleAttribute = 'event_name';
protected static ?string $recordTitleAttribute = 'event_name';
As I understood, it's for global search and when I search, it's searches like:
SELECT *
FROM "businesses"
WHERE ("event_name"::text ilike '%pup%')
and "businesses"."deleted_at" IS NULL
LIMIT 50
SELECT *
FROM "businesses"
WHERE ("event_name"::text ilike '%pup%')
and "businesses"."deleted_at" IS NULL
LIMIT 50
But I have another column for full text search with index and I one to search by query:
SELECT *
FROM "businesses"
WHERE textsearchable_index_col @ @ to_tsquery('english', 'pup:*')
and "businesses"."deleted_at" IS NULL
SELECT *
FROM "businesses"
WHERE textsearchable_index_col @ @ to_tsquery('english', 'pup:*')
and "businesses"."deleted_at" IS NULL
When I rewrite "getGlobalSearchResults":
public static function getGlobalSearchResults(string $searchQuery): Collection
{

$customResults = Business::query()
->whereRaw("textsearchable_index_col @@ to_tsquery('english', ?)", [$searchQuery.':*'])
->get();

return parent::getGlobalSearchResults($searchQuery)
->concat($customResults)
->unique()
->values();
}
public static function getGlobalSearchResults(string $searchQuery): Collection
{

$customResults = Business::query()
->whereRaw("textsearchable_index_col @@ to_tsquery('english', ?)", [$searchQuery.':*'])
->get();

return parent::getGlobalSearchResults($searchQuery)
->concat($customResults)
->unique()
->values();
}
It's searches in both variants and returns result based on first (simple "ilike" search) If I remove $recordTitleAttribute, the its shows up menu without title (I see, that getGlobalSearchResults runs - searches) So, how to enable only my getGlobalSearchResults query and return event_name as the title in search result.
5 replies
FFilament
Created by AlexAnder on 5/30/2023 in #❓┊help
Section heading text color
Is it possible to change "section" heading text color based on record?
3 replies
FFilament
Created by AlexAnder on 4/28/2023 in #❓┊help
Custom query for repeater
Hi everyone. Is it possible to create custom query for repeater?
6 replies