GithubHelp home page GithubHelp logo

belongsto-depend's Introduction

A Laravel Nova Field for dependant fields

This field is based on BelongsTo element and the idea from orlyapps/nova-belongsto-depend which served me as a base/idea to create my first custom field as i had problems implementing it on Laravel Nova 3

Installation

You should be able to install this package via composer:

composer require rumeau/belongsto-depend

No additional installation instructions are required

Usage

Once installed, you are ready to use the field on your Nova Resources

// in app/Nova/ExampleResource.php
use Rumeau\BelongstoDepend\BelongstoDepend;
use App\Nova\Category;
use App\Nova\Subcategory;

// ...

public function fields()
{
    return [
        // ...
        BelongstoDepend::make(__('Category'), 'category', Category::class),        

        BelongstoDepend::make(__('Subcategory'), 'subcategory', Subcategory::class)
                        ->dependsOn('category', 'parent_id'),
        
        // ...
    ];
}

dependsOn($dependableField, $foreignKey) method accepts two arguments:

  • $dependableField: The field that this field depends from
  • $foreignKey: A foreign key from which to filter the dependable field options

All BelongsTo core field options are available.

Finally in order to filter the dependable options you can use the core method from the resource relatable<Relation>() in order to filter the query.

Final notes

This is a work in progress as it may present some errors. So use it at your own risk.

Fork and contribute if you believe it is useful.

Thanks.

belongsto-depend's People

Contributors

rumeau avatar

Stargazers

 avatar

Watchers

 avatar  avatar

belongsto-depend's Issues

Searchable Selects Don't Trigger Depend Behaviour

Hi...

If I set a BelongsToDepend field to be searchable by adding ->searchable() to the definition, it doesn't trigger the update behaviour for the dependant selects.

For example, the following doesn't work:

BelongsToDepend::make('Manufacturer', 'manufacturer', Manufacturer::class)
    ->searchable(),

BelongsToDepend::make('Brand', 'brand', Brand::class)
    ->dependsOn('manufacturer', 'manufacturer_id'),

But If the ->searchable() is removed from the Manufacturer field, then it does.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.