Laravel Community Tools by Tighten
Laravel Nova icon Nova Packages
C

Custom Relationship Field

Readme

Custom Relationship Field

Latest Version on Packagist Total Downloads License

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 having to create a real relation between them.

Installation

You can install the package via composer:

composer require digital-creative/custom-relationship-field
use DigitalCreative\CustomRelationshipField\CustomRelationshipField;
use DigitalCreative\CustomRelationshipField\CustomRelationshipFieldTrait;

trait UserWithSimilarNameTrait
{    
    public static function similarNameQuery(NovaRequest $request, Builder $query, User $model): Builder
    { 
        return $query->where('last_name', $model->last_name)->whereKeyNot($model->getKey());
    }
    
    public function similarNameFields(NovaRequest $request): array
    {
        return [
            ID::make(),
            Text::make('First Name'),
            Text::make('Last Name'),
        ];
    }
    
    public function similarNameActions(NovaRequest $request): array 
    {
        return [];
    }

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

class User extends Resource
{    
    use CustomRelationshipFieldTrait;
    use UserWithSimilarNameTrait;
    
    public function fields(NovaRequest $request): array
    {
        return [
            ...
            CustomRelationshipField::make('Users with similar name', 'similarName', User::class),
            ...
        ];
    }
}

⭐️ Show Your Support

Please give a ⭐️ if this project helped you!

Other Packages You Might Like

License

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

Screenshots

Back to Top
Added 6 years ago
Last updated 1 Year Ago
Version v1.1.3
Nova Version ^4.0
Composer
digital-creative/custom-relationship-field
GitHub stars 33
Packagist downloads 173,809

Favorites

10 users favorited

Rating

4.20
(out of 5)
★★★★★
★★★★
★★★
★★
5 ratings

Brought to you by Tighten

Issues/Feature Requests Stats Package Ideas