Skip to content

Commit

Permalink
Fix some crashes w/ ManyToMany relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarpsvo committed Apr 22, 2020
1 parent 88bfd2f commit bf595c9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Traits/HasSortableRows.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ public static function getSortability(NovaRequest $request)
$relationshipQuery = $request->findParentModel()->{$request->viaRelationship}();

if (isset($request->resourceId)) {
$model = $relationshipQuery->withPivot('id', 'sort_order')->find($request->resourceId)->pivot;
$tempModel = $relationshipQuery->first()->pivot ?? null;
$model = !empty($tempModel) ?
$relationshipQuery->withPivot($tempModel->getKeyName(), $tempModel->sortable['order_column_name'])->find($request->resourceId)->pivot
: null;
} else {
$model = $relationshipQuery->first()->pivot;
$model = $relationshipQuery->first()->pivot ?? null;
}

$sortable = $model->sortable ?? false;
Expand Down

0 comments on commit bf595c9

Please sign in to comment.