百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
N

nova-belongsto-depend

> 前端框架
开源

Laravel Nova 的 BelongsTo 字段具有依赖关系

180 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

Laravel Nova 的 BelongsTo 字段具有依赖关系

BelongsTo Field with Dependency

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

Installation

You can install the package in to a Laravel app that uses Nova via composer:

bash
composer require orlyapps/nova-belongsto-depend

Use this field in your Nova Resource

…

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

Options

placeholder('Optional Placeholder')

openDirection('top') See options values from vue-multiselect

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:

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

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.

php
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.

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

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
…

Depend on several fields

https://user-images.githubusercontent.com/5220826/119490295-f6c9e700-bd5c-11eb-9431-92048e723201.mp4

From version 3 of this package you can depend on several fields. Just pass them comma separated in the dependsOn method.

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

Here an example:

  • Classification hasMany Models && belongsToMany Brands
  • Brand hasMany Models && belongsToMany Classification
  • Model belongsTo Classification && 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
…

Security

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

Credits

  • Orlyapps

License

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

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPlaravellaravel-novalaravel-packagevuejs

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架