Dex
Dex
FFilament
Created by Dex on 2/21/2024 in #❓┊help
Override getTableKeyRecord function
Is it possible to override this function, because I am using a view from another connection without indexes, so filament doesnt like that. I found out that I can just rewrite like
public function getTableRecordKey(Model $record): string
{
return uniqid();
}
public function getTableRecordKey(Model $record): string
{
return uniqid();
}
https://github.com/filamentphp/filament/discussions/3182 But where exactly because I don`t want to make it global in the vendor directory.
3 replies
FFilament
Created by Dex on 1/9/2024 in #❓┊help
Tables rendering in print view
Is it possible to show table head on each page and format the styling so the table breaks correctly?
4 replies
FFilament
Created by Dex on 1/9/2024 in #❓┊help
Style customization print view
Hello fellas, I am trying to Style some filament tables which work pretty well, but when I look at the preview none of the styles is working. Any idea how can I customize that or make it work?
3 replies
FFilament
Created by Dex on 8/23/2023 in #❓┊help
Updating rows of a belongsToMany relationship
Is there a possibility to update the rows of the pivot table instead of deleting the row. For example I have 2 Table: Table1 ( group ) ID NAME CHALLENGE_ID Table2 (group_users -> pivot) ID GROUP_ID USER_ID IS_GROUP
public function users(): BelongsToMany
{
return $this->belongsToMany(TenantUser::class, 'group_users', 'group_id', 'user_id')->withTimestamps();
}
public function users(): BelongsToMany
{
return $this->belongsToMany(TenantUser::class, 'group_users', 'group_id', 'user_id')->withTimestamps();
}
When I do it as follow:
protected function getFormSchema(): array
{
return [
TextInput::make('name')
->label('Name')
->required()
->autofocus()
->unique('groups', fn(): string => !isset($this->group) ? 'name' : 'id'),
Select::make('challenge_id')
->label('Challenge')
->hint('Optional')
->searchable()
->options(function (): Collection {
return Challenge::where('type', 'group')
->whereIn('id', tenant()->get_challenges()->pluck('id'))
->pluck('title', 'id');;
}),
Select::make('users')
->label('Users')
->multiple()
->searchable()
->relationship('users', 'full_name')
->preload(),
];
}
public function submit()
{
$state = $this->form->getState();
if ($this->group) {
$this->group->update($state);
} else {
$this->group = TenantGroup::create($state);
$this->form->model($this->group)->saveRelationships();
}
}
protected function getFormSchema(): array
{
return [
TextInput::make('name')
->label('Name')
->required()
->autofocus()
->unique('groups', fn(): string => !isset($this->group) ? 'name' : 'id'),
Select::make('challenge_id')
->label('Challenge')
->hint('Optional')
->searchable()
->options(function (): Collection {
return Challenge::where('type', 'group')
->whereIn('id', tenant()->get_challenges()->pluck('id'))
->pluck('title', 'id');;
}),
Select::make('users')
->label('Users')
->multiple()
->searchable()
->relationship('users', 'full_name')
->preload(),
];
}
public function submit()
{
$state = $this->form->getState();
if ($this->group) {
$this->group->update($state);
} else {
$this->group = TenantGroup::create($state);
$this->form->model($this->group)->saveRelationships();
}
}
The record will be deleted from the pivot when I remove a user, instead I would like to update the updated_at for example.
23 replies
FFilament
Created by Dex on 6/16/2023 in #❓┊help
Table record with GroupBy statement
I have the following query:
protected function getTableQuery(): Builder
{
return TenantUserActivity::select('user_activities.id', 'data.activity_module.module_id', 'user_activities.created_at', 'data.modules.title as module_title', 'data.activities.title as activity_title', 'data.activities.points')
->leftJoin('data.activities', 'data.activities.id', '=', 'user_activities.activity_id')
->leftJoin('data.activity_module', 'data.activities.id', '=', 'data.activity_module.activity_id')
->leftJoin('data.modules', 'data.activity_module.module_id', '=', 'data.modules.id')
->where('user_id', '=', Auth::user()->id)
->where('data.activities.points', '>', 0)
->groupBy('data.activity_module.module_id');
}
protected function getTableQuery(): Builder
{
return TenantUserActivity::select('user_activities.id', 'data.activity_module.module_id', 'user_activities.created_at', 'data.modules.title as module_title', 'data.activities.title as activity_title', 'data.activities.points')
->leftJoin('data.activities', 'data.activities.id', '=', 'user_activities.activity_id')
->leftJoin('data.activity_module', 'data.activities.id', '=', 'data.activity_module.activity_id')
->leftJoin('data.modules', 'data.activity_module.module_id', '=', 'data.modules.id')
->where('user_id', '=', Auth::user()->id)
->where('data.activities.points', '>', 0)
->groupBy('data.activity_module.module_id');
}
So MySQL doesn’t allow single grouping, through the strict mode, so I grouped by the whole select Params:
protected function getTableQuery(): Builder
{
return TenantUserActivity::select('user_activities.id', 'data.activity_module.module_id', 'user_activities.created_at', 'data.modules.title as module_title', 'data.activities.title as activity_title', 'data.activities.points')
->leftJoin('data.activities', 'data.activities.id', '=', 'user_activities.activity_id')
->leftJoin('data.activity_module', 'data.activities.id', '=', 'data.activity_module.activity_id')
->leftJoin('data.modules', 'data.activity_module.module_id', '=', 'data.modules.id')
->where('user_id', '=', Auth::user()->id)
->where('data.activities.points', '>', 0)
->groupBy('data.activity_module.module_id', 'user_activities.id', 'user_activities.created_at', 'data.modules.title', 'data.activities.title', 'data.activities.points');
}
protected function getTableQuery(): Builder
{
return TenantUserActivity::select('user_activities.id', 'data.activity_module.module_id', 'user_activities.created_at', 'data.modules.title as module_title', 'data.activities.title as activity_title', 'data.activities.points')
->leftJoin('data.activities', 'data.activities.id', '=', 'user_activities.activity_id')
->leftJoin('data.activity_module', 'data.activities.id', '=', 'data.activity_module.activity_id')
->leftJoin('data.modules', 'data.activity_module.module_id', '=', 'data.modules.id')
->where('user_id', '=', Auth::user()->id)
->where('data.activities.points', '>', 0)
->groupBy('data.activity_module.module_id', 'user_activities.id', 'user_activities.created_at', 'data.modules.title', 'data.activities.title', 'data.activities.points');
}
But when I select all datasets into the table, every record has his own page. How can I fix that?
1 replies