Closed deshack closed 4 years ago
A solution could be the following:
protected function mapChunk( $chunk ) {
return ActionModelCollection::make( $this->isPivotAction()
? $chunk->map->{$this->pivotRelation()->getPivotAccessor()}
: $chunk );
}
Given that ActionRequest::pivotRelation()
returns a BelongsToMany
relation.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I am seeing this issue; and the suggested fix above fixes it.
Laravel 8.37.9 Nova 3.23.2 PHP 8.0.1
Laravel Nova does come with dusk tests covering pivot action with fields on BelongsToMany relationship and it's returning green. At this point please create a full reproducing code to demonstrate the issue in case there a use case that we have yet to discover.
I ran into this issue in my current project with Nova. The proposed solution did correct the issue with the action on the pivot. I'd be happy to provide whatever information you need to identify the issue.
@Evanslooten submit new bug report using the available template.
Description:
ActionRequest::mapChunk()
doesn't take custompivot
attribute names into consideration. Therefore, when resolving the resources on which to apply the action, it populates a collection ofnull
values where pivot models should be returned. This in turn resolves in aTrying to access property <pivot foreign key> on a non-object
error inActionRequest::actionableKey()
, called byActionEvent
.Detailed steps to reproduce the issue on a fresh Nova installation:
pivot
attribute name.First model:
Second model:
Pivot model:
Action is omitted since it doesn't really matter.
MyGroupParticipantAction
action.Trying to get property
'group_id'
of non-object {"userId":1,"exception":"[object] (ErrorException(code: 0): Trying to get property 'group_id' of non-object at /path/to/nova/src/Http/Requests/ActionRequest.php:189)