© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•14mo ago•
2 replies
Jon

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');
    }

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.
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

How to Display Related Model Data on the Edit Page?
FilamentFFilament / ❓┊help
2y ago
How can I make the Data only display table?
FilamentFFilament / ❓┊help
3y ago
display data according related relationships
FilamentFFilament / ❓┊help
2y ago
Generic admin panel (not related to table/model)
FilamentFFilament / ❓┊help
2y ago