Jon
Jon
FFilament
Created by Jon on 12/19/2024 in #❓┊help
How do I only display data related to the model loaded into the panel?
Alright, i know this has been discussed before, but I am having difficulty finding the resources again. I am trying to use Filament to handle the settings pages for my users and groups in my project. I'll just discuss groups since the concept is the same in both. I created a GroupPanelprovider, So first question is where do i limit this to only display the information related to the group. Access should be granted only to users who match Group->owner_id or is a group_admin as defined in group_user table where role_id = 5 or 7 (referencing roles table) I created a middleware for this (not sure if correct, and not sure where to add this) class CheckGroupAccess { public function handle(Request $request, Closure $next) { $groupId = $request->route('group'); $user = Auth::user(); $group = Group::find($groupId); if ( ! $group) { abort(404, 'Group not found'); } if ($user->id === $group->owner_id || $user->hasRole('group_admin', $groupId) ) { return $next($request); } abort(403, 'Unauthorized access'); } Now all that should verify the user, but then I have several related models that I attached as resources, such as addresses, hours, etc. But currently these models are displaying all data instead of only the data related to the specificied group. So is there a way to have all resources query ->where(group_id,$group_id) and prevent any manual entry of a group. Or do i need to modify the query for each resource? And if for each resource, how do i reference the group_id that the panel should be displaying? This seems similar to the multi tenancy, but its between group and other models.
3 replies
FFilament
Created by Jon on 12/14/2024 in #❓┊help
How do i ignore saving of empty repeater relationship fields.
I have a repeater filed for one of my models that add s alterative names to a hobby. since not all hobbies have alternative names, this field is often empty. But if I do not manually delete the empty repeater field, I get an error that name is required. But the underlining hobby saves but without the attached media or other related items. Then if I remove the empty alt names and attempt to save again, I get an error that slug already exists. So how do i instruct filament to ignore related repeater fields if empty. If I create 5 rows, but only enter 1, It should only attempt to save 1 without error on the other 5. Also, if the underlining model is saving, shouldnt the page refresh to an update form? or have some check to save as the existing model? TextInput:: make('name') ->required() ->maxLength(255) ->live(onBlur: true) ->afterStateUpdated(function ( Get $get, Set $set, ?string $old, ?string $state ) { if (($get('slug') ?? '') !== Str::slug($old)) { return; } $set('slug', Str::slug($state)); }), // TODO slug not generating properly without the name input disappearing when typing TextInput::make('slug') ->maxLength(255) ->helperText('Generated slugs can be renamed if desired but must be unique'), Repeater::make('Alternative Names') ->label('Alternative names') ->relationship('hobbyAltNames') ->simple( TextInput::make('name'), ), ])->columnSpan(1),
12 replies
FFilament
Created by Jon on 12/12/2024 in #❓┊help
are there any packages to allow users to manipulate an image when uploading?
I am currently using the Spatie media library which has a section for manipulations in the plugin docs, but If you want "media specific" manipulations, wouldnt hat imply that the user should have an opportunity to define the manipualtion? otherwise every image uploaded through that input would end up with the manipulation. as defined in the docs ' #Storing media-specific manipulations You may pass in manipulations that are run when files are uploaded using the manipulations() method: use Filament\Forms\Components\SpatieMediaLibraryFileUpload; SpatieMediaLibraryFileUpload::make('attachments') ->multiple() ->manipulations([ 'thumb' => ['orientation' => '90'], ]) ' But how can I give the end user a chance to rotate, and set an image to a square crop where they can adjust the crop location best for the uploaded image? cropper.js seems to be the tool I need, but I don't know how to go about implementing it with Filament, or laravel in general? are there any existing plugins that handle this? Or any guidance on how to implement it within the form builder?
5 replies
FFilament
Created by Jon on 12/3/2024 in #❓┊help
where do i add custom styles for one off tables
No description
6 replies
FFilament
Created by Jon on 12/3/2024 in #❓┊help
how do I add ->with statements to the table query?
ALl the query related things in the docs seem to be to adjust individual columns. if i need to add ->withCount($this->getDemographics()) to the table data, to handle the following set up, where do i add this?
28 replies
FFilament
Created by Jon on 12/2/2024 in #❓┊help
How can I create a button to toggle a group of fields instead of utilizing the column filters
No description
6 replies
FFilament
Created by Jon on 11/30/2024 in #❓┊help
How do I add Actions to the top of a form next to delete.
No description
18 replies
FFilament
Created by Jon on 11/19/2024 in #❓┊help
How do I make text based boolean columns
If i have a boolean column that I would want to display as text instead of an icon, ->boolean doesnt exist on TEXTCOLUMN This example the column references 'is_book' where a false value would mean it is a magazine instead of a book. So I'd like the column labeled "type" to display either 'book', or 'magazine' depending on true or false.
4 replies
FFilament
Created by Jon on 11/15/2024 in #❓┊help
can someone help guide me in setting up filament for specific users or groups?
I'm fairly sure this is something to do with multi-tenacy. But in my app, I have my backend Admin panel which is fine. But I also want to use filament to handle things like user or group settings. Of course this would need to ensure that a user or group admin only has access to their data. All the documents reference teams, which is not what I am looking for, though may be the same idea.
I am just a bit lost in how to approach this. If i have a user panel, I have a few tables that all relate to user settings, but the user table itself also has multiple columns that would be better if i could split them into several sections. I currently have it set up as tabs, for just the user table data. but can those tabs be made into sidebar links in the panel? If i have a pivot table, that also has its own fields, I'd like this to also be its own form in the user panel. So admin panel manages all things related to SITE if user = admin User panel -- manages all things related to logged in user Group panel-- manages all things related to group if user = group_admin or owner Groups and users will have view access to any logged in user I just need a little help figuring out how to set up this front end panel arrangement.
4 replies
FFilament
Created by Jon on 10/23/2024 in #❓┊help
How do I filter count columns
I have a column to display member counts of a group.
TextColumn::make('active_members_count')
->label('Members')
->counts('activeMembers')
->sortable()
->grow(false)
->wrapHeader()
,
TextColumn::make('active_members_count')
->label('Members')
->counts('activeMembers')
->sortable()
->grow(false)
->wrapHeader()
,
I am attempting to allow a filter that affects this column, but I am not sure the proper way to reference it as it is a calculated value.
Filter::make('active_members_count')
->form([
Fieldset::make('Members')
->schema([
TextInput::make('min')->numeric()
->label('Min Members'),
TextInput::make('max')->numeric()
->label('Max Members'),
]),
])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['min'],
fn(
Builder $query,
$members
): Builder => $query->having('active_members_count',
'>=', $members)
)
->when(
$data['max'],
fn(
Builder $query,
$members
): Builder => $query->having('active_members_count',
'<=', $members)
);
}),
Filter::make('active_members_count')
->form([
Fieldset::make('Members')
->schema([
TextInput::make('min')->numeric()
->label('Min Members'),
TextInput::make('max')->numeric()
->label('Max Members'),
]),
])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['min'],
fn(
Builder $query,
$members
): Builder => $query->having('active_members_count',
'>=', $members)
)
->when(
$data['max'],
fn(
Builder $query,
$members
): Builder => $query->having('active_members_count',
'<=', $members)
);
}),
Thanks
3 replies
FFilament
Created by Jon on 2/10/2024 in #❓┊help
How can I save data (TAGS) into a M:M polymorphic array? I have been struggling w/ this for months
GOAL: Loop through tags (ratings) that correspond to the Hobby model: Sample data: https://imgur.com/a/WDe6Z19 An example: if the taggable table lists tag_id 2 [solo] belongs to hobby id 1 , TAG 2 would be a child to tag 1 [activity type] in which the rendered selects would simply loop through all parent ratings, and then child ratings of each and if a hobby has a child connection, it marks it as selected. Parent Tags in this case will never be a selected option, they only serve to create the input label: The child tags form the input's options Selected values need to be saved to hobbyRatings relationship which is a M:M polymorphic relationship: I have tried to make this work in several ways which i will post below. I can get the select statements to load properly, but they are not saving. Note, this ratings form is a sub form within the hobbyResource. The hobby-specific data saves, but I cannot get the rating data to save. nor do i have a clue how to view the "data" object to see how i might need to format the code differently. Any help would be greatly appreciated. To keep this short here are the questions on LARACASTS: https://laracasts.com/discuss/channels/filament/filament-v3-adding-a-livewire-component -- this attempt using livewire https://laracasts.com/discuss/channels/filament/how-do-i-manually-save-a-generated-field-with-filament --this attempt directly in the resource
2 replies
FFilament
Created by Jon on 12/6/2023 in #❓┊help
How do I create a group of SELECTs with a foreach loop
I am having trouble with my form creation in that I dont know how to go about inserting basic php to generate form data. In this instance, I want to loop through all my Rating tags in the database along with the choices for each. but I dont know how to do this within the schema The available rating options may change so it needs to be generated dynamically
Section::make('Ratings')
->schema([

foreach($model->hobbyRatings()->where('parent_id',null) as $rating){
Select::make($rating->tag)
->options(function (Builder $query) use ($rating) {
return $query->where('parent_id', $rating->id)->get();
});
}


])

->columnSpanFull(),
Section::make('Ratings')
->schema([

foreach($model->hobbyRatings()->where('parent_id',null) as $rating){
Select::make($rating->tag)
->options(function (Builder $query) use ($rating) {
return $query->where('parent_id', $rating->id)->get();
});
}


])

->columnSpanFull(),
2 replies
FFilament
Created by Jon on 12/5/2023 in #❓┊help
If I want to create panels for Users or Groups to edit their settings, is that a multitenant setup
part of my site needs front end management that allows users and or groups to manage settings specific to their profile. I figured a user and group panel might be a good way to do this, but should i be looking at multi tenant setups, or is there a better way to handle this? Also I created a vendor panel as well then set up the access as "
public function canAccessPanel(Panel $panel): bool
{
if ($panel->getId() === 'admin') {
return auth()->check()
&& auth()->user()->hasRole([
'admin', 'super-admin',
]);
}
if ($panel->getId() === 'vendor') {
return true;
}

return true;
}
public function canAccessPanel(Panel $panel): bool
{
if ($panel->getId() === 'admin') {
return auth()->check()
&& auth()->user()->hasRole([
'admin', 'super-admin',
]);
}
if ($panel->getId() === 'vendor') {
return true;
}

return true;
}
but every panel but vendor allows me to access it. Vendor panel is blocking access. No idea why. if the path is simply /vendor is their a route conflict maybe?
4 replies