PHPackages                             granello/nova-belongsto-depend - 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. [Templating &amp; Views](/categories/templating)
4. /
5. granello/nova-belongsto-depend

ActiveLibrary[Templating &amp; Views](/categories/templating)

granello/nova-belongsto-depend
==============================

A Laravel Nova field.

3.0.7(4y ago)027MITVuePHP &gt;=7.1.0

Since Nov 8Pushed 4y agoCompare

[ Source](https://github.com/studioilgranello/nova-belongsto-depend)[ Packagist](https://packagist.org/packages/granello/nova-belongsto-depend)[ RSS](/packages/granello-nova-belongsto-depend/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (7)DependenciesVersions (8)Used By (0)

BelongsTo Field with Dependency
===============================

[](#belongsto-field-with-dependency)

Cosa ho cambiato
----------------

[](#cosa-ho-cambiato)

- introdotta modifica corretta [orlyapps/nova-belongsto-depend#96](https://github.com/orlyapps/nova-belongsto-depend/issues/96)
- aggiunto quarto parametro `$parentResource` per gestire i casi in cui la risorsa Nova non ha lo stesso nome del modello Laravel.

[![Latest Version on Packagist](https://camo.githubusercontent.com/e37f51234050495ef6f0f5b95f256fb6d7e9e92d635f1681ac06a06226064262/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f726c79617070732f6e6f76612d62656c6f6e6773746f2d646570656e642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Orlyapps/nova-belongsto-depend)[![Total Downloads](https://camo.githubusercontent.com/ccc089c2dd8916590d7b52dc9629ba6db0d3b392d25238f6b69aeb042c90d886/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f726c79617070732f6e6f76612d62656c6f6e6773746f2d646570656e642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Orlyapps/nova-belongsto-depend)

[![Sample](https://raw.githubusercontent.com/orlyapps/nova-belongsto-depend/master/docs/sample.gif)](https://raw.githubusercontent.com/orlyapps/nova-belongsto-depend/master/docs/sample.gif)

Using an older version of Laravel?
----------------------------------

[](#using-an-older-version-of-laravel)

This version is compatible with Laravel 5.8 and newer.

If you use an older version of Laravel you can use an older version of the package. These aren't maintained anymore, but they should be pretty stable. We still accept small bugfixes.

- [v1 for Laravel 5.7+ / PHP 7.0](https://github.com/orlyapps/nova-belongsto-depend/releases/tag/1.0.0)

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

[](#installation)

You can install the package in to a Laravel app that uses [Nova](https://nova.laravel.com) via composer:

```
composer require orlyapps/nova-belongsto-depend
```

Use this field in your Nova Resource

```
use Orlyapps\NovaBelongsToDepend\NovaBelongsToDepend;

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),
        Text::make('Name')->rules('required', 'max:255'),

        NovaBelongsToDepend::make('Company')
            ->placeholder('Optional Placeholder') // Add this just if you want to customize the placeholder
            ->options(\App\Company::all()),
        NovaBelongsToDepend::make('Department')
            ->placeholder('Optional Placeholder') // Add this just if you want to customize the placeholder
            ->optionsResolve(function ($company) {
                // Reduce the amount of unnecessary data sent
                return $company->departments()->get(['id','name']);
            })
            ->dependsOn('Company'),
        NovaBelongsToDepend::make('Location')
            ->placeholder('Optional Placeholder') // Add this just if you want to customize the placeholder
            ->optionsResolve(function ($company) {
                // Reduce the amount of unnecessary data sent
                return $company->locations()->get(['id','name']);
            })
            ->fallback(
                Text::make('Location Name')->rules('required', 'max:255'),
            )
            ->hideLinkToResourceFromDetail()
            ->hideLinkToResourceFromIndex()
            ->nullable()
            ->dependsOn('Company'),

    ];
}
```

Options
-------

[](#options)

`placeholder('Optional Placeholder') `

`openDirection('top') `See options values from [vue-multiselect ](https://vue-multiselect.js.org/#sub-props)

Translation
-----------

[](#translation)

The following strings are translatable (add then in your language file located in resources/lan/vendor/nova/\*.json).

- 'Oops! No elements found. Consider changing the search query.'
- 'List is empty'
- 'Select'
- 'Press enter to select'
- 'Selected'
- 'Press enter to remove'

If you do use nova-translatable and would like to return the translated name add this to your translatable model:

```
    /**
     * @return mixed
     */
    public function getNameAttribute()
    {
        return $this->getTranslations('name')[app()->getLocale()];
    }
```

Performance Tips
----------------

[](#performance-tips)

When attaching this field to a resource, you may include the field relation in the `$with` property for that resource to prevent n+1 issues when loading an index page for that resource.

```
class Company extends Resource
{
  public static $with = [];
}

class Department extends Resource
{
  public static $with = ['company'];
}

class Location extends Resource
{
  public static $with = ['department', 'company'];
}
```

You may also choose to cache your top-level model to reduce the number of queries made to the database for each row in an index.

```
NovaBelongsToDepend::make('Company')
    ->options(Cache::remember(
        'companies',
        60,
        function () {
            return Company::all();
        }
    )),
NovaBelongsToDepend::make('Department')
    ->dependsOn('Company')
    ->optionsResolve(function($company) {
        return $company->departments;
    })
```

Sample
------

[](#sample)

- Warehouse hasMany Articles
- Articles belongsToMany Suppliers
- Suppliers belongsToMany Articles

1. Select a **Warehouse** and get all articles of the warehouse
2. Select a **Article** and get all suppliers who has this article

```
public function fields(Request $request)
{
    return [
        ID::make()->sortable(),
        Text::make('Name')->rules('required', 'max:255'),

        NovaBelongsToDepend::make('Warehouse')
        ->options(\App\Warehouse::all())
        ->rules('required'),
        NovaBelongsToDepend::make('Article')
            ->optionsResolve(function ($warehouse) {
                return $warehouse->articles;
            })
            ->dependsOn('Warehouse')
            ->rules('required'),
        NovaBelongsToDepend::make('Supplier')
            ->optionsResolve(function ($article) {
                return \App\Supplier::whereHas('articles', function ($q) use ($article) {
                    $q->where('article_id', $article->id);
                })->get();
            })
            ->dependsOn('Article')
            ->rules('required'),

    ];
}
```

Depend on several fields
------------------------

[](#depend-on-several-fields)

    CleanShot.2021-05-25.at.13.25.38.mp4    From **version 3** of this package you can depend on several fields. Just pass them comma separated in the dependsOn method.

```
->dependsOn('classification', 'brand')
```

Here an example:

- Classification hasMany Models &amp;&amp; belongsToMany Brands
- Brand hasMany Models &amp;&amp; belongsToMany Classification
- Model belongsTo Classification &amp;&amp; belongsTo Brand

1. Select a **Classification** and get all *Brands* of the classification
2. Select a **Brand** and get all *Models* that has this *Classification* **and** *Brand*

```
public function fields(Request $request)
{
    return [
        ID::make(__('ID'), 'id')->sortable(),
        NovaBelongsToDepend::make('Classification', 'classification')
            ->options(\App\Models\Classification::all()),
        NovaBelongsToDepend::make('Brand', 'brand')
            ->optionsResolve(function ($classification) {
                return $classification->brands()->get(['brands.id', 'brands.name']);
            })
            ->dependsOn('classification'),
        NovaBelongsToDepend::make('Model', 'model', VehicleModel::class)
            ->optionsResolve(function ($depends) {
                return \App\Models\VehicleModel::query()
                    ->where('classification_id', $depends->classification->id)
                    ->where('brand_id', $depends->brand->id)
                    ->get();
            })
            ->dependsOn('classification', 'brand'),
    ];
}
```

Security
--------

[](#security)

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

Credits
-------

[](#credits)

- [Orlyapps](https://github.com/orlyapps)

License
-------

[](#license)

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

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~0 days

Total

7

Last Release

1644d ago

### Community

Maintainers

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

---

Top Contributors

[![orlyapps](https://avatars.githubusercontent.com/u/5220826?v=4)](https://github.com/orlyapps "orlyapps (17 commits)")[![davide-cattani](https://avatars.githubusercontent.com/u/82278259?v=4)](https://github.com/davide-cattani "davide-cattani (11 commits)")[![chrisneal](https://avatars.githubusercontent.com/u/1110269?v=4)](https://github.com/chrisneal "chrisneal (4 commits)")[![PhilippeDirx](https://avatars.githubusercontent.com/u/38032711?v=4)](https://github.com/PhilippeDirx "PhilippeDirx (3 commits)")[![CasperLaiTW](https://avatars.githubusercontent.com/u/5094008?v=4)](https://github.com/CasperLaiTW "CasperLaiTW (3 commits)")[![lvdhoorn](https://avatars.githubusercontent.com/u/22305189?v=4)](https://github.com/lvdhoorn "lvdhoorn (3 commits)")[![cwilby](https://avatars.githubusercontent.com/u/13686317?v=4)](https://github.com/cwilby "cwilby (3 commits)")[![Sergej-Tihonov](https://avatars.githubusercontent.com/u/15265981?v=4)](https://github.com/Sergej-Tihonov "Sergej-Tihonov (2 commits)")[![headcrap](https://avatars.githubusercontent.com/u/503293?v=4)](https://github.com/headcrap "headcrap (1 commits)")[![darinda](https://avatars.githubusercontent.com/u/8490373?v=4)](https://github.com/darinda "darinda (1 commits)")[![glennwilton](https://avatars.githubusercontent.com/u/6619768?v=4)](https://github.com/glennwilton "glennwilton (1 commits)")[![gmedeiros](https://avatars.githubusercontent.com/u/3370868?v=4)](https://github.com/gmedeiros "gmedeiros (1 commits)")[![adilimudassir](https://avatars.githubusercontent.com/u/22865892?v=4)](https://github.com/adilimudassir "adilimudassir (1 commits)")[![mohamedary](https://avatars.githubusercontent.com/u/17085444?v=4)](https://github.com/mohamedary "mohamedary (1 commits)")[![newtongamajr](https://avatars.githubusercontent.com/u/8673343?v=4)](https://github.com/newtongamajr "newtongamajr (1 commits)")[![petyots](https://avatars.githubusercontent.com/u/14016592?v=4)](https://github.com/petyots "petyots (1 commits)")

---

Tags

laravelnova

### Embed Badge

![Health badge](/badges/granello-nova-belongsto-depend/health.svg)

```
[![Health](https://phpackages.com/badges/granello-nova-belongsto-depend/health.svg)](https://phpackages.com/packages/granello-nova-belongsto-depend)
```

###  Alternatives

[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[outl1ne/nova-multiselect-field

A multiple select field for Laravel Nova.

3402.9M2](/packages/outl1ne-nova-multiselect-field)[emilianotisato/nova-tinymce

This Nova package allow you to use TinyMCE editor for text areas.You can customize the editor options and... you can upload images to your server and put them rigth there on the text without leaving the text editor!

116884.3k4](/packages/emilianotisato-nova-tinymce)[silvanite/novafieldcheckboxes

A Laravel Nova field to display a number of multi-select options using checkboxes.

70846.9k1](/packages/silvanite-novafieldcheckboxes)[waynestate/nova-ckeditor4-field

This nova package allows you to use CKEditor 4 for text areas.

62739.1k8](/packages/waynestate-nova-ckeditor4-field)[saumini/ellipsis-textarea

A Laravel Nova textarea field with ellipsis support

12146.9k](/packages/saumini-ellipsis-textarea)

PHPackages © 2026

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