Skip to content

Can not access pivot relation in BelongsToMany Closure #3641

Answered by crynobone
mira-thakkar asked this question in Q&A
Discussion options

You must be logged in to vote

You can use the following:

public function fields(Request $request) {
    return [
        ID::make(__('ID'), 'id')->sortable(),

        Text::make('Name'),

        BelongsToMany::make('Tags')->fields(function ($request, $relatedModel) {
            return [
                Text::make('Env','env_id'),

                $this->mergeWhen($request->isResourceIndexRequest(), function () {
                    return [
                        Text::make('Status', function ($pivot) {
                            return isset($pivot) && $pivot->env_id ? 'Completed' : 'Pending';
                        }),
                    ];
                }),
            ];
        })
    ];
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mira-thakkar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #3640 on November 17, 2021 22:19.