filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
17.7k stars 2.77k forks source link

Relation Manager > format state on pivot model #14166

Closed falko100 closed 1 week ago

falko100 commented 1 week ago

Package

filament/filament

Package Version

v3.2.97

Laravel Version

v10.48.18

Livewire Version

No response

PHP Version

v8.3

Problem description

This is the table of my RelationManager. I have a many-to-many relation with a view properties on my pivot. I would like to add multiple pivot values together, but can't seem to find a way to do this.

Let's say I have a User object with a many-to-many relation with SubscriptionUser. This many-to-many has a Pivot model called SubscriptionUser and pivot fields active and expires_at:

public function table(Table $table): Table
{
    return $table
        ->allowDuplicates()
        ->columns([
            Tables\Columns\TextColumn::make('some_pivot_field')
                ->formatStateUsing(function ($state, $record) {
                    // Here I would like to access UserRole.
                    // I want to be able to see every subscription and make the `active` state orange when expires at is within a month.
                    // This is not my actual use-case.
                }),
        ]);
}

Expected behavior

public function table(Table $table): Table
{
    return $table
        ->allowDuplicates()
        ->columns([
            Tables\Columns\TextColumn::make('some_pivot_field')
                ->formatStateUsing(function ($pivot) {
                   return pivot->something_from_my_subscription_user_pivot;
                }),
        ]);
}

Steps to reproduce

  1. Make 2 models with a many-to-many relation.
  2. Add a pivot modal to the relation's use statement.
  3. Make filament resource, relation manager, attempt to get pivot specific data.

Reproduction repository (issue will be closed if this is not valid)

Not yet. Will supply if neede.

Relevant log output

No response

Donate 💰 to fund this issue

Fund with Polar

github-actions[bot] commented 1 week ago

Hey @falko100! We're sorry to hear that you've hit this issue. 💛

However, it looks like you forgot to fill in the reproduction repository URL. Can you edit your original post and then we'll look at your issue?

We need a public GitHub repository which contains a Laravel app with the minimal amount of Filament code to reproduce the problem. Please do not link to your actual project, what we need instead is a minimal reproduction in a fresh project without any unnecessary code. This means it doesn't matter if your real project is private / confidential, since we want a link to a separate, isolated reproduction. That would allow us to download it and review your bug much easier, so it can be fixed quicker. Please make sure to include a database seeder with everything we need to set the app up quickly.