PHPackages                             dive-be/nova-linkable-field - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. dive-be/nova-linkable-field

ActiveLibrary[Database &amp; ORM](/categories/database)

dive-be/nova-linkable-field
===========================

Optionally link to a different model as an alternative to a manual attribute value.

v0.2.1(3y ago)12.5kMITPHPPHP ^8.1

Since Apr 11Pushed 3y agoCompare

[ Source](https://github.com/dive-be/nova-linkable-field)[ Packagist](https://packagist.org/packages/dive-be/nova-linkable-field)[ RSS](/packages/dive-be-nova-linkable-field/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (6)Versions (8)Used By (0)

Nova Linkable Field
===================

[](#nova-linkable-field)

This package allows you to provide a field that can optionally link to a different model as an alternative to a manual attribute value.

What problem does this package solve?
-------------------------------------

[](#what-problem-does-this-package-solve)

Sometimes, you want users of the back-end to be able to either derive a value from a different model, or manually fill in the value.

If you have a model that *might* link to another model from which it derives an attribute, but also want to provide a fallback value (in case it isn't linked), that can get messy quick in the back-end. In that case you'll end up with two fields in the resource, and the user needs to understand that the fallback value is only used if the resource isn't linked to another model. Not exactly obvious.

With this package, you can provide a single field where the user can explicitly choose, leaving zero room for confusion: get the value for an attribute from a particular model, or fill it in manually. (Check out the use case below.)

Use Case
--------

[](#use-case)

For example: you have a `MenuItem` model in your application.

Maybe you want this `MenuItem` to link to a particular model (a `Page` model, perhaps?), which has its own URL. You can do that, or provide a manual URL alternative (if you do not want to link a model).

This makes it very obvious to users in Nova that the field in question is *either* linked or a fixed, manual value.

Requirements
------------

[](#requirements)

- `laravel/framework: ^9.0`
- `laravel/nova: ^3.0`

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require dive-be/nova-linkable-field
```

You can publish the migrations and configuration file with:

```
php artisan vendor:publish --provider="Dive\Nova\Linkable\FieldServiceProvider"
```

Usage
-----

[](#usage)

### Terminology

[](#terminology)

- A model can be **linked** to one or more models.
- The attached model is called the **target**, and the originator is the **linked** model.
- If *no target* is specified, the fallback value ("manual value") is used.

### Setting up the resource

[](#setting-up-the-resource)

You must publish and run the included migrations:

```
php artisan vendor:publish --provider="Dive\Nova\Linkable\FieldServiceProvider"
php artisan migrate

```

In the resource, you can choose which field you would like to use a linkable field.

```
use Dive\Nova\Linkable\Linkable;

Linkable::make('URL', 'url')
    ->withLinkable(
        Page::class, // the related model that is linked
        'CMS Page', // how the model is identified to the user
        ['title'], // columns queried for use in the callback (next parameter)
        fn ($page) => $page->getAttribute('title') // callback that resolves the display value of the related model
    ),
```

You can call the `withLinkable` method multiple times if you want to have multiple link options.

### Setting up the model

[](#setting-up-the-model)

First, let's start off with the **link** class, which is the originator. It needs the `InteractsWithLinks` trait.

```
use InteractsWithLinks;
```

So, if you have a homogenous collection that contains solely models of the same type, you can load this information. Here's how you can do this:

```
use \Dive\Nova\Linkable\LinkedCollection;

// Load the target relationships and attributes in as few queries as possible
$menuItems = LinkedCollection::create(MenuItem::all())
    ->loadLinkedData(['url']);

// Access the target (returns a model)
$menuItems->first()->linkedTargets['url'];

// Access the attribute (returns a value by calling `getLinkableValue()` on the linked target model)
$menuItems->first()->linkedAttributes['url'];
```

If you attempt to load linked relationships on a non-homogenous collection or on models that do not support linkable values, you'll get an exception explaining what went wrong.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Nico Verbruggen](https://github.com/nicoverbruggen)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~58 days

Recently: every ~73 days

Total

6

Last Release

1194d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a265853c8db7c699f64f523ee782dc5ec095bfb456379222d1b0b97d90e4c735?d=identicon)[dive](/maintainers/dive)

---

Tags

laravelmodelnova

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/dive-be-nova-linkable-field/health.svg)

```
[![Health](https://phpackages.com/badges/dive-be-nova-linkable-field/health.svg)](https://phpackages.com/packages/dive-be-nova-linkable-field)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M70](/packages/mongodb-laravel-mongodb)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)[sebastiaanluca/laravel-boolean-dates

Automatically convert Eloquent model boolean attributes to dates (and back).

40111.7k1](/packages/sebastiaanluca-laravel-boolean-dates)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
