Code Monkey home page Code Monkey logo

custom-relationship-field's Introduction

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.

custom-relationship-field's People

Contributors

dependabot[bot] avatar littlemiaor avatar milewski avatar nw-b avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

custom-relationship-field's Issues

browser crash

Im using package in nova4 and resource crashes browser after some time.

image

image

after disabling field, problem dissapear

Trait collision with ConditionalContainer

Great work!

When using together with ConditionalContainer I get following trait collision

Trait method 'availableFields' will not be applied because it collides with 'HasConditionalContainer'

Is there a way to solve this?

Pagination

Hey Rafael,

as always great stuff!

How can we add pagination to the result?

How do we use this with other models?

How would we use this with a relation other than the same model? Like for your example this only displays other clients on the client page. I'm trying to display another model that belongs to the resource being looked at that isn't related by eloquent. Thank you very much for this package!

This doesn't seem to work for me... here are some things I've tried.

This works:

$query->where('id', '<', 100);

❗ This does not:

$query = DB::table('users')
            ->where('id', '<', 100);

return $query

This works:

$query = $query
            ->leftJoin('buyer_buyers_agent AS bba', 'bba.buyer_id', '=', 'users.id')

return $query

❗ This does not:

$query = $query
            ->leftJoin('buyer_buyers_agent AS bba', 'bba.buyer_id', '=', 'users.id')
            ->where('bba.buyer_id', '<', 100)

return $query

I was expecting to customize my query. Can I make any query? What are the limitations?

Thanks!

WOW

Thank you, this is awesome!

/Tim

After updated Nova package doesn't work

Hello

First of all, I congratulate you on a job well done.

Second I wanted to open this issue because after updating to the latest version of nova 4.29.5 the package unfortunately stops working.

I attach image with the error.

Screenshot 2023-11-12 alle 14 11 20

Duplication of the CustomRelationshipField

Using CustomRelationshipField twice results in duplication of the first CustomRelationshipField e.g
CustomRelationshipField::make('Child Prefixes', 'children', self::class), CustomRelationshipField::make('Parent Prefixes', 'parents', self::class),

results in displaying the Child Prefixes Twice.

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.