gwd/nova-back-to-parent-field
A Laravel Nova field that adds a convenient "back to parent" link to resource detail and form pages, letting you quickly navigate to the parent record instead of relying on breadcrumbs or manual URL edits.
Confirm what you actually installed before writing any code. This package has no README, no marketplace listing, zero stars and a single release from 2020-08-23 — it was almost certainly built against Nova 3 (Laravel Mix era). Treat the source as the documentation.
Install and inspect:
composer require gwd/nova-back-to-parent-field
composer show gwd/nova-back-to-parent-field
cat vendor/gwd/nova-back-to-parent-field/composer.json
ls -R vendor/gwd/nova-back-to-parent-field/src vendor/gwd/nova-back-to-parent-field/resources
The three things you need from this pass: the field class namespace (likely Gwd\NovaBackToParentField\BackToParentField — verify, don't guess), the Nova version constraint, and whether a Nova::script() call exists so the Vue component is registered.
First use case — a child resource detail page with a link back to its parent, e.g. an Order detail screen linking to its Customer:
use Gwd\NovaBackToParentField\BackToParentField; // verify from src/
public function fields(Request $request)
{
return [
BackToParentField::make('Back to Customer')
->onlyOnDetail(),
BelongsTo::make('Customer', 'customer', Customer::class),
// ...
];
}
Read src/BackToParentField.php for the builder methods it exposes (parentResource(), parentId(), url() or similar). If none exist, the field infers the parent from the model relationship or from a BelongsTo field's position in the fields() array — that determines how you wire it.
If Nova 4/5 refuses to load the component (
Unknown custom elementin the console), stop here. The Vue component was compiled for Nova 3's asset pipeline and will need to be rebuilt as an ESM/Vite component. Budget for that before adopting.
Navigation-only field. Keep this field purely presentational and let a normal BelongsTo handle editing. Never ship it on forms:
BackToParentField::make('Parent')
->onlyOnDetail()
->hideWhenCreating()
->hideWhenUpdating()
->hideFromIndex(),
Explicit parent resolution. If the field doesn't infer the parent reliably (or you want to control the label and URL), resolve it yourself in the callback:
BackToParentField::make('Parent')
->onlyOnDetail()
->resolveUsing(function ($value, $resource) {
$parent = $resource->customer; // loadMissing first, see gotchas
if (! $parent) {
return null;
}
return [
'label' => "{$parent->name}",
'url' => \Laravel\Nova\Nova::path()."/resources/customers/{$parent->getKey()}",
];
});
Prefer Nova::path() / Nova::resourcePath()-style helpers over hard-coded /nova/resources/... so the field survives a change to the Nova path or a renamed resource URI key.
Multi-level hierarchies. For a tree (Category → Subcategory → Product), put the field on each level and derive the parent class from the model so a single field definition covers polymorphic parents:
$parentClass = $resource->parent_type
? Nova::resourceForModel($resource->parent_type)
: Category::class;
Wrap it, don't fork the vendor directory. Subclass it once so fixes survive composer update, or if it's already broken, copy the class plus its Vue component into your app:
namespace App\Nova\Fields;
class BackToParent extends \Gwd\NovaBackToParentField\BackToParentField
{
public function component()
{
return 'back-to-parent-field'; // your own registered component
}
}
Then register the script in a service provider: Nova::script('back-to-parent', __DIR__.'/../dist/js/back-to-parent.js').
The 10-line replacement. For Nova 4/5, the cheapest equivalent is a Text field rendered as HTML, or a small Stack:
Text::make('Parent', function () {
$p = $this->customer;
return $p
? "<a class='link-default' href='".Nova::path()."/resources/customers/{$p->getKey()}'>← {$p->name}</a>"
: '';
})->asHtml()->onlyOnDetail(),
LICENSE file exists and grep -R "curl\|Http::\|file_get_contents" src/ before putting it in a production app.composer.json for laravel/nova constraints and whether the JS is built with laravel-nova mix helpers. You cannot rebuild vendor JS from your app root — you must publish or copy it into your own asset pipeline.onlyOnDetail() you'll get a stray column and possibly errors on the create form where no parent exists yet.->sortable(false) / avoid searchable().$resource->loadMissing('customer') in the resolver, or eager-load in the resource via $this->load() / index query scoping.Gate::allows('view', $parent) (or Nova::resourceForModel() + policy check) before returning a URL — otherwise you're leaking navigable paths.Unknown custom element: <back-to-parent-field>, confirm Nova::script() runs, then php artisan nova:publish and hard-refresh. Nova caches assets; clear with php artisan view:clear plus a browser cache bust.fields() array to find a BelongsTo, place it after that field — a subtle, undocumented coupling worth a comment in your resource.composer.json ("gwd/nova-back-to-parent-field": "1.0.0") and run composer require --dry-run first to confirm it resolves against your Nova version. An unpinned abandoned package is a future composer update landmine.Text::make(...)->asHtml() or a Nova Heading/Stack with a link unless the package's component does something you genuinely can't reproduce in a dozen lines.How can I help you explore Laravel packages today?