All Projects → orlyapps → Nova Belongsto Depend

orlyapps / Nova Belongsto Depend

Licence: mit
Larave Nova BelongsTo Field with Dependcy

Projects that are alternatives of or similar to Nova Belongsto Depend

Laravel Enum
Elegant Enum implementation for Laravel
Stars: ✭ 107 (-16.41%)
Mutual labels:  laravel, laravel-package
Laravel Fpdf
Create PDFs with Laravel, provides FPDF version 1.82
Stars: ✭ 108 (-15.62%)
Mutual labels:  laravel, laravel-package
Laravel Excel
🚀 Supercharged Excel exports and imports in Laravel
Stars: ✭ 10,417 (+8038.28%)
Mutual labels:  laravel, laravel-package
Laravel Google Translate
This package makes using the Google Translate API in your laravel app a breeze with minimum to no configuration, clean syntax and a consistent package API.
Stars: ✭ 97 (-24.22%)
Mutual labels:  laravel, laravel-package
Pagination
🎁 Laravel 5 Custom Pagination Presenter
Stars: ✭ 119 (-7.03%)
Mutual labels:  laravel, laravel-package
Elasticsearch Eloquent
⚡️ Eloquent models for Elasticsearch.
Stars: ✭ 100 (-21.87%)
Mutual labels:  laravel, laravel-package
Nova Indicator Field
A colour-coded indicator field for Laravel Nova
Stars: ✭ 108 (-15.62%)
Mutual labels:  laravel, laravel-package
Dropzone Laravel Image Upload
Laravel 5.2 and Dropzone.js auto image uploads with removal links
Stars: ✭ 92 (-28.12%)
Mutual labels:  laravel, laravel-package
Laravel Natural Language
This package makes using the Google Natural API in your laravel app a breeze with minimum to no configuration, clean syntax and a consistent package API.
Stars: ✭ 119 (-7.03%)
Mutual labels:  laravel, laravel-package
Eye
Eyewitness.io package for Laravel 5 applications
Stars: ✭ 114 (-10.94%)
Mutual labels:  laravel, laravel-package
Laravel Tracer
Shows the path of each blade file loaded in a template
Stars: ✭ 96 (-25%)
Mutual labels:  laravel, laravel-package
Laravel Meta
Metadata for Eloquent model
Stars: ✭ 124 (-3.12%)
Mutual labels:  laravel, laravel-package
Lara Lens
Laravel package for display diagnostic (config, database, http connections...)
Stars: ✭ 96 (-25%)
Mutual labels:  laravel, laravel-package
Laravel Stats
📈 Get insights about your Laravel or Lumen Project
Stars: ✭ 1,386 (+982.81%)
Mutual labels:  laravel, laravel-package
Admin One Laravel Dashboard
Admin One — Free Laravel Dashboard (Bulma Buefy Vue.js SPA)
Stars: ✭ 94 (-26.56%)
Mutual labels:  laravel, laravel-package
Cray
A Laravel package to help you generate nearly complete CRUD pages like crazy!
Stars: ✭ 108 (-15.62%)
Mutual labels:  laravel, laravel-package
Laravel Sync Migration
Developer tool helps to sync migrations without refreshing the database
Stars: ✭ 89 (-30.47%)
Mutual labels:  laravel, laravel-package
Laravel Rest Api
Powerful RestAPI plugin for Laravel
Stars: ✭ 90 (-29.69%)
Mutual labels:  laravel, laravel-package
Laravel Geo Routes
GeoLocation restricted routes for Laravel
Stars: ✭ 110 (-14.06%)
Mutual labels:  laravel, laravel-package
Laravel Mail Editor
MailEclipse ⚡ Laravel Mailable Editor!
Stars: ✭ 1,714 (+1239.06%)
Mutual labels:  laravel, laravel-package

BelongsTo Field with Dependency

Latest Version on Packagist Total Downloads

Sample

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.

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

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

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:

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

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 [email protected] instead of using the issue tracker.

Credits

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].