Marcelo Andrade
Marcelo Andrade
FFilament
Created by Marcelo Andrade on 6/3/2024 in #❓┊help
Public API to access data of a resource with filters
Found a way in case someone is interested:
public function handle()
{
$filterSets = UserView::whereIsGlobalFavorite(true)->get();

$user = User::findOrFail(1);
auth()->login($user);

$subjectsToUpdate = [];
/** @var UserView $filterSet */
foreach ($filterSets as $filterSet) {
echo $filterSet->name, PHP_EOL;

/** @var SubjectResource\Pages\ListSubjects $livewire */
$livewire = app(SubjectResource\Pages\ListSubjects::class);
$livewire->tableFilters = $filterSet->filters['tableFilters'];
$livewire->tableDeferredFilters = $filterSet->filters['tableFilters'];
$livewire->bootedInteractsWithTable();
$livewire->applyTableFilters();

/** @var Builder $query */
$query = $livewire->getFilteredSortedTableQuery();
$records = $livewire->getTableRecords();
foreach ($records as $subject) {
$subjectId = $subject->id;
if (array_key_exists($subjectId, $subjectsToUpdate)) {
$subjectsToUpdate[$subjectId] = array_merge($subjectsToUpdate[$subjectId], [$filterSet->id => $filterSet->name]);
} else {
$subjectsToUpdate[$subjectId] = [$filterSet->id => $filterSet->name];
}
}
}

foreach ($subjectsToUpdate as $subjectId => $filtersMatched) {
$subject = Subject::findOrFail($subjectId);
$subject->user_views = array_values($filtersMatched);
$subject->save();
}
}
public function handle()
{
$filterSets = UserView::whereIsGlobalFavorite(true)->get();

$user = User::findOrFail(1);
auth()->login($user);

$subjectsToUpdate = [];
/** @var UserView $filterSet */
foreach ($filterSets as $filterSet) {
echo $filterSet->name, PHP_EOL;

/** @var SubjectResource\Pages\ListSubjects $livewire */
$livewire = app(SubjectResource\Pages\ListSubjects::class);
$livewire->tableFilters = $filterSet->filters['tableFilters'];
$livewire->tableDeferredFilters = $filterSet->filters['tableFilters'];
$livewire->bootedInteractsWithTable();
$livewire->applyTableFilters();

/** @var Builder $query */
$query = $livewire->getFilteredSortedTableQuery();
$records = $livewire->getTableRecords();
foreach ($records as $subject) {
$subjectId = $subject->id;
if (array_key_exists($subjectId, $subjectsToUpdate)) {
$subjectsToUpdate[$subjectId] = array_merge($subjectsToUpdate[$subjectId], [$filterSet->id => $filterSet->name]);
} else {
$subjectsToUpdate[$subjectId] = [$filterSet->id => $filterSet->name];
}
}
}

foreach ($subjectsToUpdate as $subjectId => $filtersMatched) {
$subject = Subject::findOrFail($subjectId);
$subject->user_views = array_values($filtersMatched);
$subject->save();
}
}
4 replies
FFilament
Created by milkslices on 6/4/2024 in #❓┊help
Programmatically change the values of a single Livewire component form action
You inject the Set object to the action handler to set something on the form: https://filamentphp.com/docs/3.x/forms/actions#form-component-action-utility-injection
5 replies
FFilament
Created by Marcelo Andrade on 5/31/2024 in #❓┊help
Is it possible to render a RepeatableEntry as a table, without duplicating the labels
Thank you for the guidance
3 replies