orlyapps / nova-belongsto-depend

Larave Nova BelongsTo Field with Dependcy
MIT License
182 stars 65 forks source link

Not working on Nova 3 #65

Closed rumeau closed 3 years ago

rumeau commented 4 years ago

Does it support Nova 3?

It fails loading options on dependant field as resourceParentClass is never set

everestmx commented 4 years ago

+1

rumeau commented 4 years ago

I've managed to make it work adding a method setResourceParentClass() to explicitly set the resourceParentClass property on the dependant field.

newtongamajr commented 4 years ago

@rumeau Could you please leave us here a segment of code that you used to work around the problem? I'm stuck on a solution for this! Thanks!

rumeau commented 4 years ago

Hello @newtongamajr

Actually i've just added a method to NovaBelongsToDepend

   /**
     * @param $parentResourceClass
     * @return self
     */
    public function setResourceParentClass($parentResourceClass)
    {
        $this->resourceParentClass = $parentResourceClass;
        return $this;
    }

And pass the resource name explicitly to that method

NovaBelongsToDepend::make(__('Subcategory'), 'subcategory', Subcategory::class)
    ->setResourceParentClass(self::class)
    ->dependsOn('category');

Actually im not sure if thats the only think i did because i've finally ended up creating my own custom field.

I have uploaded to github and packagist in case you want to give it a try.

I haven't tested it in every scenario but it does what i needed, and you can work over it.

https://github.com/rumeau/belongsto-depend

composer require rumeau/belongsto-depend

Greetings

mdavis1982 commented 4 years ago

@orlyapps Is this something that will be looked at at all? Thanks! 😄

newtongamajr commented 4 years ago

@rumeau , Thanks for your work around, and I'll give a try on your new package!

Dandula commented 4 years ago

+1

orlyapps commented 4 years ago

Hello everyone. Thanks for the issue. We currently dont have any nova 3.0 installation. So we would be very happy about a pull request! I can merge it asap as new version!

orlyapps commented 4 years ago

Hello, i have upgraded to Nova 3.0 but im seeing no issues? Can you please explain whats happing?

henryavila commented 4 years ago

@orlyapps , I'm having the same issue. The list simple don't display the names: image

And when I select one, the console log shows: image

Here are my code

NovaBelongsToDepend::make(__('Tenant'), 'tenant', NovaTenant::class)
                ->placeholder(__('Select a Tenant'))
                ->options(Tenant::all())

I'm using Laravel v7.20.0 and Laravel Nova 3.7.1