orlyapps / nova-belongsto-depend

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

Not working with 2 BelongsTo Fields #83

Open mattjamesvogt opened 3 years ago

mattjamesvogt commented 3 years ago

Thanks for creating this, looks like a great repo!

I can't get it to work with 2 BelongsTo fields.

Order User Company

Order has belongsTo for both Company and User.

public function company()
{
    return $this->belongsTo(Company::class);
}

public function user()
{
    return $this->belongsTo(User::class);
}

Have set it up like this:

NovaBelongsToDepend::make('Company')
    ->options(\App\Models\Company::all()),

NovaBelongsToDepend::make('User')
->optionsResolve(function ($company) {
    return $company->users()->get();
})
->dependsOn('company'),

User field never shows, even after selecting a company

Thanks!

mohamedary commented 3 years ago

I ended up having the same issue. I wonder if it's version related or am I missing something.

imnpc commented 3 years ago
            NovaBelongsToDepend::make('Customer')
                ->options(\App\Models\Customer::all())
                ->rules('required'),
            NovaBelongsToDepend::make('Project')
                ->optionsResolve(function ($customer) {
                    return $customer->project;
                })
                ->dependsOn('customer')
                ->rules('required'),

today test this ok

cweiske commented 2 years ago

Works here with laravel/nova 3.31.0 and orlyapps/nova-belongsto-depend 3.0.2.