Lomkit / laravel-rest-api

Generate Api in seconds
https://laravel-rest-api.lomkit.com/
MIT License
298 stars 18 forks source link

Error searchQuery when using laravel/spatie-permission #48

Closed Samoht70 closed 8 months ago

Samoht70 commented 9 months ago

Laravel Rest Api Version

1.1.1

Laravel Version

10.24.0

PHP Version

8.1

Database Driver & Version

No response

Description

Error: Call to a member function resource() on null in file /var/www/vendor/lomkit/laravel-rest-api/src/Http/Response.php on line 92

This error occurs when using laravel/spatie-permission. By including roles in the User model via the variable $with because the relationship with roles is defined directly with the package, so I didn't define it in the UserResource.

Steps To Reproduce

GautierDele commented 9 months ago

I'm not getting a crash on my side, can you confirm this is still hapenning on last commit please ?

GautierDele commented 9 months ago

Ok I got it, basically you are forcing a relation thats not in the relations part

Will need a bit more time to think on how to approach this

Samoht70 commented 8 months ago

"message": "Undefined array key \"includes\"", "file": "/var/www/vendor/lomkit/laravel-rest-api/src/Http/Response.php", "line": 46, The problem arises when there's a $with in the model, because the relationship is loaded by the $with but not by the includes field.