Skip to content

Commit

Permalink
Add missing relationship error message
Browse files Browse the repository at this point in the history
  • Loading branch information
dillingham committed Dec 28, 2020
1 parent 58fc969 commit 0d02e3b
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/Http/Controllers/AttachController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@ public function create(NovaRequest $request, $parent, $relationship)

public function edit(NovaRequest $request, $parent, $parentId, $relationship)
{
// lookup the resource
$foundResource = $request->findResourceOrFail();

// if the $relationship() method exists, we will use that to
// determine the keyName
if(method_exists($foundResource->model(), $relationship)){
$keyName = $foundResource->model()->{$relationship}()->getModel()->getKeyName();
// otherwise default to an assumed keyName of `id`
}else{
$keyName = 'id';
if(! method_exists($foundResource->model(), $relationship)) {
abort(500, class_basename($foundResource->model()) . " is missing relationship: $relationship");
}

$keyName = $foundResource->model()->{$relationship}()->getModel()->getKeyName();

return [
'selected' => $foundResource->model()->{$relationship}->pluck($keyName),
'available' => $this->getAvailableResources($request, $relationship),
Expand All @@ -55,7 +51,7 @@ public function getAvailableResources($request, $relationship)
return $field->formatAssociatableResource($request, $resource);
})->sortBy('display')->values();
}

/**
* Get the associatable query method name.
*
Expand Down

0 comments on commit 0d02e3b

Please sign in to comment.