Larave Nova BelongsTo Field with Dependcy
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist Compile assets Feb 7, 2019
docs sample gif Aug 31, 2018
resources Fixed issue #28 Feb 7, 2019
routes init Aug 31, 2018
src Support nova-tab Nov 30, 2018
.gitignore init Aug 31, 2018
LICENSE.md init Aug 31, 2018
README.md fixed typo Sep 7, 2018
composer.json init Aug 31, 2018
mix-manifest.json init Aug 31, 2018
package.json init Aug 31, 2018
webpack.mix.js Added option 'setPublicPath' to prevent issue with compiling Feb 7, 2019

README.md

BelongsTo Field with Dependency

Latest Version on Packagist Total Downloads

Sample

Installation

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

composer require orlyapps/nova-belongsto-depend

Use this field in your Nova Resource

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

        NovaBelongsToDepend::make('Company')
            ->options(\App\Company::all()),
        NovaBelongsToDepend::make('Department')
            ->optionsResolve(function ($company) {
                // Reduce the amount of unnecessary data sent
                return $company->departments()->get(['id','name']);
            })
            ->dependsOn('Company'),
        NovaBelongsToDepend::make('Location')
            ->optionsResolve(function ($company) {
                // Reduce the amount of unnecessary data sent
                return $company->locations()->get(['id','name']);
            })
            ->dependsOn('Company'),

    ];
}

Sample

Demo Project

  • 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'),


    ];
}

Security

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

Credits

License

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