laravel-json-api / laravel

JSON:API for Laravel applications
MIT License
541 stars 41 forks source link

Unable to encode compound document. See previous exception for cause of failure. #263

Closed Pok09 closed 10 months ago

Pok09 commented 10 months ago

I want to use it with orchid.software

I configured everything correctly, but can't get it to work properly

`Unable to encode compound document. See previous exception for cause of 01

Pok09 commented 10 months ago

The same error on a fresh installation of laravel

lindyhopchris commented 10 months ago

See previous exception for cause of failure

In your logs, there will be the previous exception which is the cause of the failure. What does that say?

lindyhopchris commented 10 months ago

Closing this - you need to refer to the previous exception for the cause of the failure. That'll be in your logs.

FYI the next version of this package - v3.2 - will remove the catching of the original exception and just let that bubble up, rather than the cause being in the previous exception.

veneliniliev commented 10 months ago

@lindyhopchris I have the same problem in the following case and with eager loading:

two fields with the same type:

HasOne::make('metric')->type('inventory-metrics'), HasOne::make('metric-service', 'metricService')->type('inventory-metrics'),

in model:

public function metric(): HasOne { return $this->hasOne(Metric::class, 'id', 'metric_id'); } public function metricService(): HasOne { return $this->hasOne(Metric::class, 'id', 'metric_service_id'); }

in AppServiceProvider I have Model::preventLazyLoading()

I include both relations in the query!

include=metric,metric-service

and throw an exception: Attempted to lazy load [metric] on model

lindyhopchris commented 10 months ago

@veneliniliev are you using our controller action, or have you written your own controller action?

veneliniliev commented 10 months ago

@veneliniliev are you using our controller action, or have you written your own controller action?

i use LaravelJsonApi\Laravel\Http\Controllers\JsonApiController

lindyhopchris commented 10 months ago

And the error is originating from something that is returned from that controller by the package's code, and not your own?

If so, can you create a separate issue as it is unrelated to this issue.