Can not access pivot relation in BelongsToMany Closure #3641
Answered
by
crynobone
mira-thakkar
asked this question in
Q&A
-
Description:Can not access pivot relation within BelongsToMany fields closure Detailed steps to reproduce the issue on a fresh Nova installation:Post Model
Post Resource
Same way i have created the Tag Model and Tag resource I tried the same files in another project having laravel version Any help would be appreciated, |
Beta Was this translation helpful? Give feedback.
Answered by
crynobone
Nov 18, 2021
Replies: 1 comment
-
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';
}),
];
}),
];
})
];
} |
Beta Was this translation helpful? Give feedback.
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
You can use the following: