inertiajs / inertia-laravel

The Laravel adapter for Inertia.js.
https://inertiajs.com
MIT License
2.08k stars 234 forks source link

Inertia Testing does not load eager loaded relations properly #509

Closed felixele217 closed 1 year ago

felixele217 commented 1 year ago

Hey guys,

for managing permission and roles we are using the awesome laravel-permission package from Spatie.

When we send a User-Model to the frontend (we are using react), we want roles.permissions to be attached always.

Therefore we added the following to our User-Model:

image

If we inspect with React Devtools in Frontend, we see the following:

image

Now we wrote the following test to assert, that this is happening properly:

image

But the test fails and says the following:

image

And if we dd() the response we see this:

image

Somehow the permissions are not loaded with the roles but seperate in the test. Is this functionality missing for the Inertia-Testing feature or am I doing it wrong somehow?

Any help appreciated! Greetings Felix

flavio-paqt commented 1 year ago

Did you check both documentations? Did you remove 0 and tested it again?

How can we reproduce this?

aknEvrnky commented 1 year ago

How you pass the object to frontend? Do you use api resource which is created by php artisan make:resource. It is possible to that converting the object to json may be differs when it is handled by laravel.

As I see, in your frontend root object which is auth is an object. But in your backend it is an array.

willard-wpu commented 1 year ago

you can use API Resource

jessarcher commented 1 year ago

Hey there,

We're closing this issue because it's inactive, already solved, old or not relevant anymore. Feel to open up a new issue if you're still experiencing this problem.