ziffmedia / nova-select-plus

A Laravel Nova Select Field
MIT License
91 stars 26 forks source link

Call to undefined method ... newModel() #48

Closed manuele89 closed 1 year ago

manuele89 commented 1 year ago

I have this error: "Call to undefined method App \ Models \ Tags:: newModel () "

I need this: associate tags (already present in the tags table) to the user, storing the association in the pivot_user_tags table

this is my code:

in app/Nova/User.php fields: SelectPlus::make('Tags', 'tags', 'App\Models\Tags')->label('title'),

in app/Models/Tags.php

public function tags()
    {
        return $this->belongsToMany('App\Models\Tags', 'pivot_user_tags table', 'user_id', 'tag_id');
    }

when i go to edit user, i get the error: Call to undefined method App \ Models \ Tags:: newModel ()

can you help me?

rea-dan commented 1 year ago

+1

ralphschindler commented 1 year ago

Try changing the 3rd parameter to SelectPlus::make(...) to App\Nova\Tags or Tags::class where Tags is the Nova Resource. The resources goes there, not the Model itself.