anjama
anjama
FFilament
Created by anjama on 9/1/2024 in #❓┊help
Restoring repeater soft delete
TLDR: Is it possible to make it so that adding new repeater elements will recycle soft deleted rows in a pivot table first? Or would it fundamentally be a bad idea for a repeater to recycle soft deleted rows? Background: My app is setup so that everything is soft-deleted and referenced by shadow tables for data history and recovery. The only place where I'm concerned with my implementation is in the pivot tables for many-to-many relationships. The soft delete and shadow table all works, but if data is deleted, and then new elements are added to the repeater, it's added as new rows in the pivot table. This leads to a situation where I can accumulate a bunch of dead rows in the data, and makes developing a way to explore the history and restore an old state more difficult. It seems like ideally I would want to recycle soft-deleted rows first before creating new ones.
2 replies
FFilament
Created by anjama on 4/20/2024 in #❓┊help
Create child entries in RelationManager on view page of parent resource
I have a CreateAction for a RelationManager to a child resource, but it only shows up if a user navigates to the edit page of the parent resource (same with edit and delete actions in the RelationManager). It does not show up on the view page for the parent resource. This means users have to be given permissions to edit the parent resource when they shouldn't be able to do so. Am I missing something to enable adding child entries via the RelationManger from the view page of the parent resource?
5 replies
FFilament
Created by anjama on 4/18/2024 in #❓┊help
Handling null id in column url to related resource
I'm using urls in my tables to allow quick navigation to the views of related records. Here's an example:
TextColumn::make('bird_id')->sortable()->searchable()
->url(fn (Capture $record): string => BirdResource::getUrl('view', ['record' => $record->bird_id]))
TextColumn::make('bird_id')->sortable()->searchable()
->url(fn (Capture $record): string => BirdResource::getUrl('view', ['record' => $record->bird_id]))
It generally works great, but in one of my tables the column of related ids has null values. These null values cause errors, so they have to be handled. What would be a good approach to conditionally showing these urls when the values are not null?
5 replies
FFilament
Created by anjama on 12/27/2023 in #❓┊help
Creating table filter in a trait
I have a table filter that works perfectly when created directly in my resources, but fails when I try to move it to a trait (I have multiple resources with the same filter).
trait SoftDeleteFilter
{
public static function softDeleteFilter()
{
return Filter::make('is_deleted')
->label('Deleted')
->baseQuery(fn (Builder $query) => $query->withoutGlobalScopes([
SoftDeleteScope::class,
]))
->toggle()
->query(function (Builder $query, array $data): Builder {
return $query->whereHas('activity_log', fn (Builder $query) => $query->where('activity', '=', ActionEnum::Delete));
});
}
}
trait SoftDeleteFilter
{
public static function softDeleteFilter()
{
return Filter::make('is_deleted')
->label('Deleted')
->baseQuery(fn (Builder $query) => $query->withoutGlobalScopes([
SoftDeleteScope::class,
]))
->toggle()
->query(function (Builder $query, array $data): Builder {
return $query->whereHas('activity_log', fn (Builder $query) => $query->where('activity', '=', ActionEnum::Delete));
});
}
}
How I'm calling it:
->filters([
self::softDeleteFilter()
])
->filters([
self::softDeleteFilter()
])
Doesn't cause an error; just basically clears the table. I suspect I'm messing up something related to static methods, but I'm not sure. Can anyone point out what my mistake is? Would it be a better approach to just extend the Filter class similar to how the trashed filter extends the ternary filter class? Thanks
5 replies
FFilament
Created by anjama on 8/22/2023 in #❓┊help
Laravel Excel not running in action
I have a csv importer built using Laravel Excel that works when tested in a seeder and in Tinker, but when using it with a file upload form inside of a modal, it seems like it's being skipped entirely inside of the action (doesn't even throw exceptions when there is an issue). Other code before and after the import inside of the action runs fine. Can anyone spot something I'm doing wrong?
Action::make('import')
->form([
FileUpload::make('data_file')
->acceptedFileTypes(['text/csv'])
->maxFiles(1)
->storeFileNamesIn('file_name')
])
->action(function (array $data): void {
//dd($data);
//try {
Excel::import(new SitesImport, 'test_data/test_sites.csv'); //Manual file name for debugging
//} catch (ValidationException $e) {
// dd($e->failures());
//}

Notification::make()
->title('Imported: ' . $data['file_name'])
->success()
->send();
})
Action::make('import')
->form([
FileUpload::make('data_file')
->acceptedFileTypes(['text/csv'])
->maxFiles(1)
->storeFileNamesIn('file_name')
])
->action(function (array $data): void {
//dd($data);
//try {
Excel::import(new SitesImport, 'test_data/test_sites.csv'); //Manual file name for debugging
//} catch (ValidationException $e) {
// dd($e->failures());
//}

Notification::make()
->title('Imported: ' . $data['file_name'])
->success()
->send();
})
22 replies
FFilament
Created by anjama on 8/8/2023 in #❓┊help
Design question: multiple panels?
So I'm new to filament and trying to wrap my head around the best way to use it. I'm designing a data management app with no public facing components. There will be an Owner role, an Admin role, and a User role. The idea is the Owner is mostly going to be hands off and will designate Admins, who will normally be the ones responsible for managing users and their permissions for accessing the data. The Owner and Admins will have full access to the data, whereas Users will have varying permissions. My question is, does it make sense to wrap everything under a single panel and prevent User access to certain admin specific pages, or is it better to split the Users out to a separate panel?
3 replies