PHPackages                             orlyapps/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. [Admin Panels](/categories/admin)
4. /
5. orlyapps/nova-belongsto-depend

ActiveLibrary[Admin Panels](/categories/admin)

orlyapps/nova-belongsto-depend
==============================

A Laravel Nova field.

3.0.4(3y ago)181841.6k↓15.8%62[38 issues](https://github.com/orlyapps/nova-belongsto-depend/issues)[1 PRs](https://github.com/orlyapps/nova-belongsto-depend/pulls)1MITPHPPHP &gt;=7.1.0

Since Aug 31Pushed 2y ago3 watchersCompare

[ Source](https://github.com/orlyapps/nova-belongsto-depend)[ Packagist](https://packagist.org/packages/orlyapps/nova-belongsto-depend)[ RSS](/packages/orlyapps-nova-belongsto-depend/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)DependenciesVersions (34)Used By (1)

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

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

[![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'),

    ];
}
```

Method `dependsOn` takes the `name` property of the fields it depends on. Use the field's `attribute` value if you specified it manually.

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

46

—

FairBetter than 93% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity56

Moderate usage in the ecosystem

Community29

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor4

4 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 ~45 days

Recently: every ~98 days

Total

32

Last Release

1427d ago

Major Versions

0.0.8 → 1.0.02019-02-21

1.0.0 → 2.02019-03-11

2.0.15 → 3.0.0-beta2021-05-12

### Community

Maintainers

![](https://www.gravatar.com/avatar/151910418d1ae1eb29a6bbeb788ea67c1ee0c77a1c02a2a437372a52da5739c4?d=identicon)[orlyapps](/maintainers/orlyapps)

---

Top Contributors

[![orlyapps](https://avatars.githubusercontent.com/u/5220826?v=4)](https://github.com/orlyapps "orlyapps (17 commits)")[![chrisneal](https://avatars.githubusercontent.com/u/1110269?v=4)](https://github.com/chrisneal "chrisneal (4 commits)")[![CasperLaiTW](https://avatars.githubusercontent.com/u/5094008?v=4)](https://github.com/CasperLaiTW "CasperLaiTW (3 commits)")[![PhilippeDirx](https://avatars.githubusercontent.com/u/38032711?v=4)](https://github.com/PhilippeDirx "PhilippeDirx (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)")[![ricklambrechts](https://avatars.githubusercontent.com/u/1367665?v=4)](https://github.com/ricklambrechts "ricklambrechts (2 commits)")[![Sergej-Tihonov](https://avatars.githubusercontent.com/u/15265981?v=4)](https://github.com/Sergej-Tihonov "Sergej-Tihonov (2 commits)")[![hellokfk](https://avatars.githubusercontent.com/u/44089201?v=4)](https://github.com/hellokfk "hellokfk (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)")[![headcrap](https://avatars.githubusercontent.com/u/503293?v=4)](https://github.com/headcrap "headcrap (1 commits)")[![cooljet84](https://avatars.githubusercontent.com/u/25043420?v=4)](https://github.com/cooljet84 "cooljet84 (1 commits)")[![crynobone](https://avatars.githubusercontent.com/u/172966?v=4)](https://github.com/crynobone "crynobone (1 commits)")[![cweiske](https://avatars.githubusercontent.com/u/59036?v=4)](https://github.com/cweiske "cweiske (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)")

---

Tags

laravellaravel-novalaravel-packagevuejslaravelnova

### Embed Badge

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

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

###  Alternatives

[benjacho/belongs-to-many-field

belongsToMany nova representation in field.

158811.4k1](/packages/benjacho-belongs-to-many-field)[pdmfc/nova-action-button

A Laravel Nova field to run actions.

37733.0k1](/packages/pdmfc-nova-action-button)[khalin/nova-link-field

A Laravel Nova Link field.

31562.2k2](/packages/khalin-nova-link-field)[ebess/nova-collapsible-sidebar

A collapsible sidebar for Laravel Nova.

32313.2k](/packages/ebess-nova-collapsible-sidebar)

PHPackages © 2026

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