ericmp
ericmp
FFilament
Created by ericmp on 7/5/2024 in #❓┊help
Collapse All Table Row Groups By Default
im trying to figure out if there is a way to collapse all groups by default in a filament table with groups + summaries is it possible? https://github.com/filamentphp/filament/discussions/10717
1 replies
FFilament
Created by ericmp on 7/3/2024 in #❓┊help
How to debounce entangled x-model?
i created a custom field. this is how i entangle the state:
x-data="{ state: $wire.entangle('{{ $getStatePath() }}').defer }"
x-data="{ state: $wire.entangle('{{ $getStatePath() }}').defer }"
but like this i cant get the state when i apply afterStateUpdated on my filament form field. if i make it like this (without defer), it works:
x-data="{ state: $wire.entangle('{{ $getStatePath() }}') }"
x-data="{ state: $wire.entangle('{{ $getStatePath() }}') }"
but obviously i dont want it this way, since im calling an api and dont wanna call it every second, so this is what im trying now:
x-data="{ state: $wire.entangle('{{ $getStatePath() }}').live.debounce.500ms }"
x-data="{ state: $wire.entangle('{{ $getStatePath() }}').live.debounce.500ms }"
but it doesnt work what im doing wrong?? im checking this docs: https://livewire.laravel.com/docs/wire-model#all-available-modifiers https://livewire.laravel.com/docs/alpine#sharing-state-using-wireentangle
50 replies
FFilament
Created by ericmp on 7/3/2024 in #❓┊help
Script Doesnt Load When Using Modals
No description
17 replies
FFilament
Created by ericmp on 6/28/2024 in #❓┊help
Creating spatie media library collections dynamically
Till now, a user only had one profile pic. But now, for each season (for example on september we start a new season), users have to upload a different profile pic. I have a Season model, where seasons name, start and end at fields are stored. Currenty, the user pic is stored in a spatie medialibrary collection - 'profilePicture' So my question is how to handle this with spatie medialibrary? I was thinking of creating dynamic spatie medialib collections: 'profilePictureSeason1' (where 1 is the id of the season) 'profilePictureSeason2' etc then, everywhere i need to retrieve the user profile pic ill just use this fn (pseudocode): getProfilePic(seasonid) return $this->getFirstMediaUrl("profilePicture{$seasonId}") What do u think? U think its fine like this or u'd do it different?
5 replies
FFilament
Created by ericmp on 6/27/2024 in #❓┊help
Trouble trying to summarize
in my members table resource im trying to coun how many id_test i have what im trying:
Tables\Columns\TextColumn::make('id_test')
->summarize(Tables\Columns\Summarizers\Count::make())
->searchable(),
Tables\Columns\TextColumn::make('id_test')
->summarize(Tables\Columns\Summarizers\Count::make())
->searchable(),
what i get afaik i go to the table in the frontend:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`members`' at line 1

SELECT
count(bgcrm.members.id_test) AS "r9YurdB29qr0ftXE"
FROM
(
SELECT
*
FROM
`bgcrm`.`members`
WHERE
`bgcrm`.`members`.`deleted_at` IS NULL
ORDER BY
`bgcrm`.`members`.`id` ASC
limit
10 OFFSET 0
) AS `bgcrm`.`members`;
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`members`' at line 1

SELECT
count(bgcrm.members.id_test) AS "r9YurdB29qr0ftXE"
FROM
(
SELECT
*
FROM
`bgcrm`.`members`
WHERE
`bgcrm`.`members`.`deleted_at` IS NULL
ORDER BY
`bgcrm`.`members`.`id` ASC
limit
10 OFFSET 0
) AS `bgcrm`.`members`;
i've found the issue but idk how to solve it. my Member model uses this as table name protected $table = 'bgcrm.members';, and i cannot change it. but if i change it to: protected $table = 'members';, it works i cannot change it cuz i need it to make relationships to work when working with relationships between different databases. if i change it to protected $table = 'members'; then some relationships wont work cuz they'll search on their default db database, and i need them to search in bgcrm database
4 replies
FFilament
Created by ericmp on 6/25/2024 in #❓┊help
Which one would u use & why?
public function data(Closure|array $data): static
{
if (is_callable($data)) {
$this->data = call_user_func($data); // A
$this->data = $data(); // or B?
} else {
$this->data = $data;
}

return $this;
}
public function data(Closure|array $data): static
{
if (is_callable($data)) {
$this->data = call_user_func($data); // A
$this->data = $data(); // or B?
} else {
$this->data = $data;
}

return $this;
}
also, u see any improvements on this code, or is it okay?
13 replies
FFilament
Created by ericmp on 6/20/2024 in #❓┊help
modalSubmitActionLabel on v2 equivalent?
on v3, in an action, u do: ->modalSubmitActionLabel('hi') on v2 idk how to do it: i try: ->modalSubmitAction(fn ($action) => $action->label('hi')) i get: Filament\Support\Actions\Action::getModalSubmitAction(): Return value must be of type Filament\Support\Actions\Modal\Actions\Action, Filament\Tables\Actions\Action returned the objective is to change the submit button label
6 replies
FFilament
Created by ericmp on 6/18/2024 in #❓┊help
Add Selector On Admin Panel's Navbar
i want to add a selector on admin panel's navbar to let the user choose one of the options. on change, ill set the value on the session. u know any workaround to do it with filament admin panel?
6 replies
FFilament
Created by ericmp on 6/14/2024 in #❓┊help
Filament v4
im about to start a new project in a couple weeks or little more. the thing is idk if start doing it with filament v3 or delay the start of it a bit to start it using v4 🤔 what would u do? i think ill start with v3 and then lets see how to update to v4 - i guess wont be a headache
4 replies
FFilament
Created by ericmp on 6/11/2024 in #❓┊help
Relationship repeater not working
No description
27 replies
FFilament
Created by ericmp on 6/5/2024 in #❓┊help
How to collapse sidebar in filament php by default
16 replies
FFilament
Created by ericmp on 6/5/2024 in #❓┊help
modifyQueryUsing breaks ToggleColumn
in the app/Filament/Resources/FormResource.php file i set up the table:
public static function table(Table $table): Table
{
return $table
->modifyQueryUsing(function (Builder $query) {
$query->when(! auth()->user()->isAdmin(), function ($query) {
$query->whereHas('users', function ($query) {
$query->where('users.id', auth()->id());
});
$query->orWhere('created_by_id', auth()->id());
});
})
->columns([
Tables\Columns\ToggleColumn::make('is_active')
...
public static function table(Table $table): Table
{
return $table
->modifyQueryUsing(function (Builder $query) {
$query->when(! auth()->user()->isAdmin(), function ($query) {
$query->whereHas('users', function ($query) {
$query->where('users.id', auth()->id());
});
$query->orWhere('created_by_id', auth()->id());
});
})
->columns([
Tables\Columns\ToggleColumn::make('is_active')
...
if the user is not admin, i want to show their created forms or the forms they are attached to. the issue is that when i modify the query, if the user is admin, works just fine, but if the user is not admin, if the user toggles the is_active column, it toggles the last row being shown in the table! https://filamentphp.com/docs/3.x/panels/resources/listing-records#customizing-the-table-eloquent-query i think the issue is related to the or. why? because if i change the orWhere to a where, the toggle works fine, but then the query is not the query i want. im doing something wrong or it's actually a bug? update: i also tried it this way. this way makes the toggles to not change
->query(function (Builder $query) {
return static::getEloquentQuery()->when(! auth()->user()->isAdmin(), function ($query) {
$query->whereHas('users', function ($query) {
$query->where('users.id', auth()->id());
});
$query->orWhere('created_by_id', auth()->id());
});
})
->query(function (Builder $query) {
return static::getEloquentQuery()->when(! auth()->user()->isAdmin(), function ($query) {
$query->whereHas('users', function ($query) {
$query->where('users.id', auth()->id());
});
$query->orWhere('created_by_id', auth()->id());
});
})
51 replies
FFilament
Created by ericmp on 6/3/2024 in #❓┊help
How to disable logging for Filament Notifications
Is there a way to disable the filament notifications logging? I'm using them via admin panel
// laravel.log
[2024-06-03 10:12:22] local.INFO: Broadcasting [database-notifications.sent] on channels [private-App.Models.User.1] with payload:
{
"user": {
"id": 1,
...
// laravel.log
[2024-06-03 10:12:22] local.INFO: Broadcasting [database-notifications.sent] on channels [private-App.Models.User.1] with payload:
{
"user": {
"id": 1,
...
23 replies
FFilament
Created by ericmp on 5/31/2024 in #❓┊help
Import csv on relation manager, how to refresh table after importing?
https://filamentphp.com/community/how-to-refresh-widgets-when-table-actions-are-fired im trying to follow it but applying it into my case. my case: import action on a relation manager table - refresh the table once the importation has finished code:
// app/Filament/Resources/EventResource/RelationManagers/ContactsRelationManager.php
protected $listeners = ['refreshContactsRelationManagerTable' => '$refresh'];
// app/Filament/Resources/EventResource/RelationManagers/ContactsRelationManager.php
protected $listeners = ['refreshContactsRelationManagerTable' => '$refresh'];
(https://filamentphp.com/docs/3.x/actions/prebuilt-actions/import#lifecycle-hooks)
// app/Filament/Imports/ContactsImporter.php
protected function afterSave(): void
{
$this->emit('refreshContactsRelationManagerTable');
}
// app/Filament/Imports/ContactsImporter.php
protected function afterSave(): void
{
$this->emit('refreshContactsRelationManagerTable');
}
but the table doesnt reload. i guess this is because it depends on the notification that has been sent. so im not sure how to emit it also in the notification or something similar
10 replies
FFilament
Created by ericmp on 5/31/2024 in #❓┊help
Error when importing
related question: https://discord.com/channels/883083792112300104/1245632711922815066 i upload the csv and all the rows fail. not sure what im missing csv:
name,surname,email,company
eric,mp,em@test.com,Test company
name,surname,email,company
eric,mp,em@test.com,Test company
local.ERROR: SQLSTATE[22003]: Numeric value out of range: 1264 Out of range value for column 'attempts' at row 1 (Connection: mysql, SQL: update `jobs` set `reserved_at` = 1717144796, `attempts` = 256 where `id` = 256) {"userId":1,"exception":"[object] (Illuminate\\Database\\QueryException(code: 22003)
local.ERROR: SQLSTATE[22003]: Numeric value out of range: 1264 Out of range value for column 'attempts' at row 1 (Connection: mysql, SQL: update `jobs` set `reserved_at` = 1717144796, `attempts` = 256 where `id` = 256) {"userId":1,"exception":"[object] (Illuminate\\Database\\QueryException(code: 22003)
Tables\Actions\ImportAction::make('importContacts')
->importer(ContactsImporter::class)
->options([
'ownerRecordId' => $this->getOwnerRecord()->id
]),
Tables\Actions\ImportAction::make('importContacts')
->importer(ContactsImporter::class)
->options([
'ownerRecordId' => $this->getOwnerRecord()->id
]),
<?php

namespace App\Filament\Imports;

use App\Models\Contact;
use App\Models\EventContact;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;

class ContactsImporter extends Importer
{
protected static ?string $model = Contact::class;

public static function getColumns(): array
{
return [
ImportColumn::make('name')
->requiredMapping()
->rules(['required', 'max:255']),
ImportColumn::make('surname')
->requiredMapping()
->rules(['required', 'max:255']),
ImportColumn::make('email')
->requiredMapping()
->rules(['required', 'max:255', 'email']),
ImportColumn::make('company')
->requiredMapping()
->rules(['required', 'max:255']),
];
}

public function resolveRecord(): ?Contact
{
$contact = Contact::firstOrNew([
'email' => $this->data['email'],
]);

EventContact::updateOrCreate([
'contact_id' => $contact->id,
'event_id' => $this->options['ownerRecordId'],
]);

return $contact;
}
}
<?php

namespace App\Filament\Imports;

use App\Models\Contact;
use App\Models\EventContact;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;

class ContactsImporter extends Importer
{
protected static ?string $model = Contact::class;

public static function getColumns(): array
{
return [
ImportColumn::make('name')
->requiredMapping()
->rules(['required', 'max:255']),
ImportColumn::make('surname')
->requiredMapping()
->rules(['required', 'max:255']),
ImportColumn::make('email')
->requiredMapping()
->rules(['required', 'max:255', 'email']),
ImportColumn::make('company')
->requiredMapping()
->rules(['required', 'max:255']),
];
}

public function resolveRecord(): ?Contact
{
$contact = Contact::firstOrNew([
'email' => $this->data['email'],
]);

EventContact::updateOrCreate([
'contact_id' => $contact->id,
'event_id' => $this->options['ownerRecordId'],
]);

return $contact;
}
}
10 replies
FFilament
Created by ericmp on 5/30/2024 in #❓┊help
How to get ownerRecord inside RecordImporter?
Lets setup 2 models. Event & People. The relationship is n to n. Inside the edit component of the event resource i added a relation manager - PeopleRelationManager. Now i started to configure the PeopleImporter so my users can import people into the event they are editing. The question is, can I somehow get the ownerRecord so i can attach the people imported to the current event? So far it works (the models are created), but the people arent attached to the event this is how it looks so far:
->headerActions([
Tables\Actions\ImportAction::make('importPeople')->importer(PeopleImporter::class),
])
->headerActions([
Tables\Actions\ImportAction::make('importPeople')->importer(PeopleImporter::class),
])
now i'm trying to pass in somehow the id of the event, but idk how to retrieve it inside the PeopleImporter class:
->headerActions([
Tables\Actions\ImportAction::make('importPeople')->importer(PeopleImporter::class)->call([
'ownerRecord' => $this->getOwnerRecord(),
]),
])
->headerActions([
Tables\Actions\ImportAction::make('importPeople')->importer(PeopleImporter::class)->call([
'ownerRecord' => $this->getOwnerRecord(),
]),
])
13 replies
FFilament
Created by ericmp on 5/29/2024 in #❓┊help
Continuation of this conversation
5 replies
FFilament
Created by ericmp on 5/17/2024 in #❓┊help
Grid view loses headers
https://filamentphp.com/docs/3.x/tables/layout#arranging-records-into-a-grid When i use the grid layout, then the table loses the headers. In my case, I need to show to the user the field names of the values that are being shown in each record in the grid for example: table mode:
id n cp
2 4 45
[more rows here]
[more rows here]
id n cp
2 4 45
[more rows here]
[more rows here]
in grid mode:
2 34 more columns here
4 5
45 1
2 34 more columns here
4 5
45 1
in this grid mode, the user has to remember which field name is which one, otherwise they see only numbers so id like to achieve something like this:
id id
2 34 more columns here

n n
4 5

cp cp
45 1
id id
2 34 more columns here

n n
4 5

cp cp
45 1
should i use an infolist for that somehow? what should i do?
19 replies
FFilament
Created by ericmp on 5/14/2024 in #❓┊help
Eloquent orWhere question
$oneDayAgo = now()->subDay();
$twoDaysAgo = now()->subDays(2);
$threeDaysAgo = now()->subDays(3);
$oneDayAgo = now()->subDay();
$twoDaysAgo = now()->subDays(2);
$threeDaysAgo = now()->subDays(3);
is this part of an eloquent query
->where(function ($q) use ($oneDayAgo, $twoDaysAgo, $threeDaysAgo) {
$q->orWhereDate('created_at', $oneDayAgo);
$q->orWhereDate('created_at', $twoDaysAgo);
$q->orWhereDate('created_at', $threeDaysAgo);
})
->where(function ($q) use ($oneDayAgo, $twoDaysAgo, $threeDaysAgo) {
$q->orWhereDate('created_at', $oneDayAgo);
$q->orWhereDate('created_at', $twoDaysAgo);
$q->orWhereDate('created_at', $threeDaysAgo);
})
the same as this?
->where(function ($q) use ($oneDayAgo, $twoDaysAgo, $threeDaysAgo) {
$q->whereDate('created_at', $oneDayAgo);
$q->orWhereDate('created_at', $twoDaysAgo);
$q->orWhereDate('created_at', $threeDaysAgo);
})
->where(function ($q) use ($oneDayAgo, $twoDaysAgo, $threeDaysAgo) {
$q->whereDate('created_at', $oneDayAgo);
$q->orWhereDate('created_at', $twoDaysAgo);
$q->orWhereDate('created_at', $threeDaysAgo);
})
the difference is on the first orWhereDate/orWhere the objective is to retrieve the records that their creation date is 1 day ago or 2 or 3 days ago so all of them are OR but one of them must be true i've searched it and i understand they are the same, but im not confident it is. what u'd say?
15 replies
FFilament
Created by ericmp on 5/7/2024 in #❓┊help
Way To Use Filters Outside a Filament Table?
I'm in a custom admin panel filament view, and i need to apply filters to the data im showing to the user. Currently im doing it via applying HasForms & InteractsWithForms to the custom page. then, im using the form as a filter. i dont submit the form, i just await for the fields to be changed and then i apply my sort based on that the question is, is there a way to bring the filament table filter outside the table so can be used as an independent filter that can be applied to a custom page somehow and not depends on a table?
5 replies