All Projects → dcasia → custom-relationship-field

dcasia / custom-relationship-field

Licence: MIT license
Emulate HasMany relationship without having a real relationship set between resources

Programming Languages

PHP
23972 projects - #3 most used programming language
Vue
7211 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to custom-relationship-field

Nova Tags Field
A tags field to use in your Nova apps
Stars: ✭ 204 (+1033.33%)
Mutual labels:  nova
nova-money-field
Money Field for Laravel Nova
Stars: ✭ 71 (+294.44%)
Mutual labels:  nova
nova-file-upload-field
The easiest drag-and-drop file uploading field for Laravel Nova.
Stars: ✭ 53 (+194.44%)
Mutual labels:  nova
Aos Avp
NOVA opeN sOurce Video plAyer: main repository to build them all
Stars: ✭ 229 (+1172.22%)
Mutual labels:  nova
android-thinkmap-treeview
Tree View; Mind map; Think map; tree map; custom view; 自定义;关系图;树状图;思维导图;组织机构图;层次图
Stars: ✭ 314 (+1644.44%)
Mutual labels:  relationship
nova-algolia-card
A Laravel Nova card for Algolia
Stars: ✭ 22 (+22.22%)
Mutual labels:  nova
Nova Filemanager
A Filemanager tool for Laravel Nova
Stars: ✭ 189 (+950%)
Mutual labels:  nova
nova-inline-morph-to
A Laravel Nova field for displaying morphTo relationship inline.
Stars: ✭ 32 (+77.78%)
Mutual labels:  nova
nova-relationship-selector
Laravel Nova - Relationship Selector
Stars: ✭ 26 (+44.44%)
Mutual labels:  nova
nova-select-plus
A Laravel Nova Select Field
Stars: ✭ 67 (+272.22%)
Mutual labels:  nova
AsyncOpenStackClient
Asyncio wrapper to OpenStack API
Stars: ✭ 17 (-5.56%)
Mutual labels:  nova
checkout
Laravel Cart, Checkout, Orders and Coupons API with Nova Management
Stars: ✭ 36 (+100%)
Mutual labels:  nova
nova-phone-number
A Laravel Nova field to format and validate phone numbers.
Stars: ✭ 60 (+233.33%)
Mutual labels:  nova
Nova Colors
Single source of truth to consume Nova color values
Stars: ✭ 217 (+1105.56%)
Mutual labels:  nova
nova-json-schema-field
Laravel Nova field for displaying JSON schema data
Stars: ✭ 27 (+50%)
Mutual labels:  nova
Skeleton Nova Tool
A skeleton repository for Spatie's Nova Packages
Stars: ✭ 191 (+961.11%)
Mutual labels:  nova
nova-permissions
Add Permissions based authorization for your Nova installation via User-based Roles and Permissions. Roles are defined in the database whereas Permissions are defined in the code base.
Stars: ✭ 115 (+538.89%)
Mutual labels:  nova
nova-unlayer-field
🦜 Drag’n’drop email builder for Laravel Nova that uses Adds a Laravel Nova field for Unlayer service under the hood.
Stars: ✭ 27 (+50%)
Mutual labels:  nova
nova-json-wrapper
Allows you to group Nova fields and merge their output into a single JSON column
Stars: ✭ 14 (-22.22%)
Mutual labels:  nova
nova-chartjs
A Chart JS component for Laravel Nova
Stars: ✭ 47 (+161.11%)
Mutual labels:  nova

Custom Relationship Field

Latest Version on Packagist Total Downloads License

Laravel Nova Custom Relationship Field in action

This field works just like as the default HasMany relationship field from nova but without requiring a real relation with the resource.

That means you are free to show resource A into the details page of resource B without they having a real bound though the standard relationship in laravel.

Installation

You can install the package via composer:

composer require digital-creative/custom-relationship-field
  1. Add the CustomRelationshipFieldTrait to the resource (A) that will be related to, and implement the required: (instance) relationFields, (static) relationQuery methods and optional: relationActions, relationFilters instance methods on it, where relation is the name you choose for your custom relation.
  2. Next, add the CustomRelationshipField to any resources (B) that you want the custom relation to be listed on the details page of.
    Example: CustomRelationshipField::make('Relation Label', 'relation', RelatedResourceA::class) where relation is the name you choose for your custom relation. Make sure you use the same relation name passed to the field to name the methods you implemented on the related resource in the first step. RelatedResourceA is the Nova resource class you are relating to which has the CustomRelationshipFieldTrait.

In the example below, the related resource is the same one that is being related to.

use DigitalCreative\CustomRelationshipField\CustomRelationshipField;
use DigitalCreative\CustomRelationshipField\CustomRelationshipFieldTrait;

class Client extends Resource
{
    
    use CustomRelationshipFieldTrait;
   
    public function fields()
    {
        return [
            Text::make('Name')->rules('required'),
            // ...
            CustomRelationshipField::make('Clients with similar name', 'similarName', self::class),
        ];
    }

    public function similarNameFields(): array
    {
        return [
            ID::make()->sortable(),
            Text::make('Name'),
            Text::make('Age'),
            //...
        ];
    }

    public static function similarNameQuery(NovaRequest $request, $query, Model $model)
    { 
        return $query->where('name', 'SOUNDS LIKE', $model->name)->whereKeyNot($model->getKey());
    }
    
    public function similarNameActions(NovaRequest $request) 
    {
        return [];
    }

    public function similarNameFilters(NovaRequest $request)
    {
        return [];
    }

}

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