Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependable MorphTo will not work correctly (again) #85

Closed
preliot opened this issue Oct 10, 2019 · 11 comments
Closed

Dependable MorphTo will not work correctly (again) #85

preliot opened this issue Oct 10, 2019 · 11 comments
Labels
bug Something isn't working confirmed This issue has been confirmed and reproduceable

Comments

@preliot
Copy link

preliot commented Oct 10, 2019

I've recently updated to Nova 2.4.0 and issue #62 seemed to be resolved. I can select the client or department without any issue. However, when i try to save this resource I get an error:

[2019-10-10 15:47:19] local.ERROR: Class 'locations' not found {"userId":201,"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Class 'locations' not found at <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Concerns\\HasRelationships.php:720)

When i leave out the dependable container, the fields work like expected. Problem is in this file:

//file: <source_dir>\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasRelationships.php 

/**
     * Define a polymorphic, inverse one-to-one or many relationship.
     *
     * @param  string  $name
     * @param  string  $type
     * @param  string  $id
     * @param  string  $ownerKey
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
     */
    public function morphTo($name = null, $type = null, $id = null, $ownerKey = null)
    {
        // If no name is provided, we will use the backtrace to get the function name
        // since that is most likely the name of the polymorphic interface. We can
        // use that to get both the class and foreign key that will be utilized.
        $name = $name ?: $this->guessBelongsToRelation();

        [$type, $id] = $this->getMorphs(
            Str::snake($name), $type, $id
        );

        // If the type value is null it is probably safe to assume we're eager loading
        // the relationship. In this case we'll just pass in a dummy query where we
        // need to remove any eager loads that may already be defined on a model.
        return empty($class = $this->{$type})
                    ? $this->morphEagerTo($name, $type, $id, $ownerKey)
                    : $this->morphInstanceTo($class, $name, $type, $id, $ownerKey);
    }

When $class is set, the first time i see a real class path. Second time function is called, $class is set to 'plural name of resource' and a string is passed. Hence the error.

stacktrace:

#0 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Concerns\\HasRelationships.php(270): Illuminate\\Database\\Eloquent\\Model->newRelatedInstance('locations')
#1 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Concerns\\HasRelationships.php(238): Illuminate\\Database\\Eloquent\\Model->morphInstanceTo('locations', 'org_level', 'org_level_type', 'org_level_id', NULL)
#2 <source_dir>\\app\\Models\\User.php(258): Illuminate\\Database\\Eloquent\\Model->morphTo()
#3 <source_dir>\
ova\\src\\Fields\\MorphTo.php(258): App\\Models\\User->org_level()
#4 <source_dir>\\vendor\\epartment\
ova-dependency-container\\src\\NovaDependencyContainer.php(195): Laravel\\Nova\\Fields\\MorphTo->fill(Object(Laravel\\Nova\\Http\\Requests\\CreateResourceRequest), Object(App\\Models\\User))
#5 <source_dir>\
ova\\src\\Fields\\Field.php(338): Epartment\\NovaDependencyContainer\\NovaDependencyContainer->fillAttributeFromRequest(Object(Laravel\\Nova\\Http\\Requests\\CreateResourceRequest), '', Object(App\\Models\\User), '')
#6 <source_dir>\
ova\\src\\Fields\\Field.php(317): Laravel\\Nova\\Fields\\Field->fillAttribute(Object(Laravel\\Nova\\Http\\Requests\\CreateResourceRequest), '', Object(App\\Models\\User), '')
#7 <source_dir>\
ova\\src\\Fields\\Field.php(291): Laravel\\Nova\\Fields\\Field->fillInto(Object(Laravel\\Nova\\Http\\Requests\\CreateResourceRequest), Object(App\\Models\\User), '')
#8 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\HigherOrderCollectionProxy.php(60): Laravel\\Nova\\Fields\\Field->fill(Object(Laravel\\Nova\\Http\\Requests\\CreateResourceRequest), Object(App\\Models\\User))
#9 [internal function]: Illuminate\\Support\\HigherOrderCollectionProxy->Illuminate\\Support\\{closure}(Object(Epartment\\NovaDependencyContainer\\NovaDependencyContainer), 6)
#10 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\Collection.php(1120): array_map(Object(Closure), Array, Array)
#11 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\HigherOrderCollectionProxy.php(61): Illuminate\\Support\\Collection->map(Object(Closure))
#12 <source_dir>\
ova\\src\\FillsFields.php(67): Illuminate\\Support\\HigherOrderCollectionProxy->__call('fill', Array)
#13 <source_dir>\
ova\\src\\FillsFields.php(20): Laravel\\Nova\\Resource::fillFields(Object(Laravel\\Nova\\Http\\Requests\\CreateResourceRequest), Object(App\\Models\\User), Object(Laravel\\Nova\\Fields\\FieldCollection))
#14 <source_dir>\
ova\\src\\Http\\Controllers\\ResourceStoreController.php(28): Laravel\\Nova\\Resource::fill(Object(Laravel\\Nova\\Http\\Requests\\CreateResourceRequest), Object(App\\Models\\User))
#15 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Concerns\\ManagesTransactions.php(29): Laravel\\Nova\\Http\\Controllers\\ResourceStoreController->Laravel\\Nova\\Http\\Controllers\\{closure}(Object(Illuminate\\Database\\MySqlConnection))
#16 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\DatabaseManager.php(349): Illuminate\\Database\\Connection->transaction(Object(Closure))
#17 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\Facades\\Facade.php(239): Illuminate\\Database\\DatabaseManager->__call('transaction', Array)
#18 <source_dir>\
ova\\src\\Http\\Controllers\\ResourceStoreController.php(44): Illuminate\\Support\\Facades\\Facade::__callStatic('transaction', Array)
#19 [internal function]: Laravel\\Nova\\Http\\Controllers\\ResourceStoreController->handle(Object(Laravel\\Nova\\Http\\Requests\\CreateResourceRequest), 'users')
#20 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Controller.php(54): call_user_func_array(Array, Array)
#21 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\ControllerDispatcher.php(45): Illuminate\\Routing\\Controller->callAction('handle', Array)
#22 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php(219): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(Laravel\\Nova\\Http\\Controllers\\ResourceStoreController), 'handle')
#23 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php(176): Illuminate\\Routing\\Route->runController()
#24 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(680): Illuminate\\Routing\\Route->run()
#25 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(30): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#26 <source_dir>\
ova\\src\\Http\\Middleware\\Authorize.php(18): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#27 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Laravel\\Nova\\Http\\Middleware\\Authorize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#28 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#29 <source_dir>\
ova\\src\\Http\\Middleware\\BootTools.php(20): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#30 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Laravel\\Nova\\Http\\Middleware\\BootTools->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#31 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#32 <source_dir>\
ova\\src\\Http\\Middleware\\DispatchServingNovaEvent.php(20): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#33 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Laravel\\Nova\\Http\\Middleware\\DispatchServingNovaEvent->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#34 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#35 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Auth\\Middleware\\Authenticate.php(43): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#36 <source_dir>\
ova\\src\\Http\\Middleware\\Authenticate.php(31): Illuminate\\Auth\\Middleware\\Authenticate->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#37 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Laravel\\Nova\\Http\\Middleware\\Authenticate->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#38 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#39 <source_dir>\\app\\Http\\Middleware\\Localize.php(39): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#40 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): App\\Http\\Middleware\\Localize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#41 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#42 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Middleware\\SubstituteBindings.php(41): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#43 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#44 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#45 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken.php(75): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#46 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#47 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#48 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\View\\Middleware\\ShareErrorsFromSession.php(49): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#49 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#50 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#51 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Session\\Middleware\\StartSession.php(56): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#52 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Session\\Middleware\\StartSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#53 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#54 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse.php(37): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#55 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#56 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#57 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\EncryptCookies.php(66): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#58 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#59 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#60 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(104): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#61 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(682): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#62 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(657): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
#63 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(623): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
#64 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(612): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
#65 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(176): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
#66 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(30): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))
#67 <source_dir>\
ova\\src\\Http\\Middleware\\ServeNova.php(26): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#68 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Laravel\\Nova\\Http\\Middleware\\ServeNova->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#69 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#70 <source_dir>\\vendor\\barryvdh\\laravel-debugbar\\src\\Middleware\\InjectDebugbar.php(58): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#71 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Barryvdh\\Debugbar\\Middleware\\InjectDebugbar->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#72 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#73 <source_dir>\\vendor\\fideloper\\proxy\\src\\TrustProxies.php(57): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#74 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Fideloper\\Proxy\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#75 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#76 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(21): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#77 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#78 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#79 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(21): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#80 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#81 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#82 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#83 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#84 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#85 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode.php(62): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#86 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#87 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#88 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(104): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#89 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(151): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#90 <source_dir>\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(116): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#91 <source_dir>\\public\\index.php(55): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#92 {main}
"} 
@preliot
Copy link
Author

preliot commented Oct 11, 2019

@wize-wiz I am not using a BelongsTo, but a MorphTo field. There is no third parameter that i'm aware of. This is the piece of code (a bit simplified):

        $fields[] = NovaDependencyContainer::make([
            Fields\MorphTo::make(__('Orglevel'), 'org_level')
            ->types([
                \App\Nova\Client\Department::class,
                \App\Nova\Client\Location::class
            ])
            ->onlyOnForms()
        ])->dependsOn('user_type', (string) Enums\UserType::CLIENT_ORG_USER);

wize-wiz added a commit that referenced this issue Oct 17, 2019
@wize-wiz
Copy link
Contributor

wize-wiz commented Oct 17, 2019

I am not using a BelongsTo, but a MorphTo field.

@preliot Sja ik was een beetje in de war, sorry ;)

MorphTo relation should now work in 1.2.7. I have tested it in Nova 2.3/2.3.1/2.4/2.5.

Please verify and if solved, close this issue.

@wize-wiz wize-wiz added bug Something isn't working confirmed This issue has been confirmed and reproduceable labels Oct 17, 2019
@preliot
Copy link
Author

preliot commented Oct 17, 2019

@wize-wiz will check soon and confirm my findings.

Die Niederländische sprache ist eine nette Geste, woher wusstest du das?

@wize-wiz
Copy link
Contributor

@preliot I can smell you're Dutch from afar 😄

Ik ben geboren en getogen in Nederland 😉

@preliot
Copy link
Author

preliot commented Oct 17, 2019

@wize-wiz I gues it's that time again ... my yearly shower awaits me!

@preliot
Copy link
Author

preliot commented Oct 22, 2019

Update to latest version and issue changed. Now i don't get an error, but no message in the frontend. My browser dev tools reveals a validation issue.

I see this message in the xhr request:

{"message":"The given data was invalid.","errors":{"org_level_type":["org level type is ongeldig."]}}

So now it seems to be a validation issue. Org_level is still a morphTo and underneath are the form fields send to the application:

org_level: 5
org_level_type: clients
org_level_trashed: false

@wize-wiz
Copy link
Contributor

Yea I noticed, I'll push a fix soon when I'm done with some other issues.

@wize-wiz
Copy link
Contributor

@preliot Should be fixed in 1.2.8, please confirm and if so, close this issue.

@preliot
Copy link
Author

preliot commented Oct 25, 2019

Unfortunatly, now i'm back at the original issue:

Xhr request:

{message: "Server Error"}
message: "Server Error"

Laravel log file:

[2019-10-25 09:02:50] local.INFO: 2019-10-25 09:02:50 | message: Class 'locations' not found | file: <source_dir>\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasRelationships.php | line: 720 | code: 0

@wize-wiz
Copy link
Contributor

wize-wiz commented Oct 25, 2019

@preliot I currently do not have any problems with the MorphTo field.

My current test version is a default setup from the Laravel documentation One To Many (Polymorphic)

// this is resource `Comment` with table fields `commentable_id` and `commentable_type` 

Select::make('Some Select', 'some_select')
    ->options([
        'a' => 'A',
        'b' => 'B'
    ])
    ->displayUsingLabels()
,

NovaDependencyContainer::make([
    MorphTo::make('Commentable')->types([
        Post::class,
        Video::class,
    ])
    ,

    Currency::make('Dependency Price', 'dprice')
    ,

    NovaDependencyContainer::make([
        Select::make('Depedenct Select', 'additional')
            ->options([
                'a' => 'A',
                'b' => 'B'
            ])
            ->displayUsingLabels()
            ->rules('required')
    ])
    ->dependsOn('commentable', 'Video')
])
->dependsOn('some_select', 'a')

Could you give me a minimal database structure and resource/model setup and a static/translated version of the following?

        $fields[] = NovaDependencyContainer::make([
            // what value is `__('Orglevel')
            Fields\MorphTo::make(__('Orglevel'), 'org_level') 
            ->types([
                \App\Nova\Client\Department::class,
                \App\Nova\Client\Location::class
            ])
            ->onlyOnForms()
        // what value is `(string) Enums\UserType::CLIENT_ORG_USER`
        ])->dependsOn('user_type', (string) Enums\UserType::CLIENT_ORG_USER);

@preliot
Copy link
Author

preliot commented Nov 14, 2019

@wize-wiz I've decided to move away from the issue. Still using this package, but this specific issue is no longer there. Thanks for all your efforts!

@preliot preliot closed this as completed Nov 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working confirmed This issue has been confirmed and reproduceable
Projects
None yet
Development

No branches or pull requests

2 participants