Laravel Community Tools by Tighten
Laravel Nova icon Nova Packages
C

Creatable BelongsTo Field

Readme

Creatable BelongsTo Field for Laravel Nova

BelongsTo Field for Laravel Nova which allows to choose or create a resource

Latest Stable Version Total Downloads Latest Unstable Version License StyleCI

Use Case

Ever had the following database structure and did not want the user to create the related resource (product_types) seperatly since it only consists of a unique name. But you don't want to put the product_type directly in the products table, since it would violate the third normal form.

Database setup example

This package solves this, by keeping the original belongsTo field but allowing the user to create a new resource by simply entering a not yet existing name. Additionally it includes the prepopulate-searchable package from alexbowers.

Installation

composer require sparclex/nova-creatable-belongs-to

Add field inside your fields Array. The parameters consist of the same ones as the laravel nova belongsTo field with an additional nameAttribute which determines the name of the display attribute in the related model (default: name).

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),
        CreatableBelongsTo::make('ProductType', 'productType', 'App\Nova\ProductType', 'name')
            ->prepopulate()
    ];
}

TODO

  • Tests
  • Respect policies for creation

License

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

Back to Top
Added 7 years ago
Last updated 6 Years Ago
Version 1.0.3
Nova Version 2.*
Composer
sparclex/nova-creatable-belongs-to
GitHub stars 14
Packagist downloads 1,851

Favorites

4 users favorited

Rating

5.00
(out of 5)
★★★★★
★★★★
★★★
★★
2 ratings

Contributors

Brought to you by Tighten

Issues/Feature Requests Stats Package Ideas