CristalTeam / php-api-wrapper

:rainbow: Work with APIs like with Laravel Eloquent or Doctrine (no longer a dream)
MIT License
119 stars 32 forks source link

Related resource id #12

Open mathieufrh opened 4 years ago

mathieufrh commented 4 years ago

What is the motivation behind this localKey attribute ?

https://github.com/CristalTeam/php-api-wrapper/blob/4f52883e250b8ea4b38c7c6b09d0ead6a0c562cb/src/Bridges/Laravel/Relations/HasMany.php#L23

I have created my database and models the Laravel's way and my relationships keys looks like "relatedModel_id" more than "id". Hence, it is working if I change the previously mentioned line to:

        $this->localKey = Str::singular($this->parent->getEntity()) . '_' . $localKey;

Also, is this package intended to be used with the JSON:API specifications ? My remote API is using these specifications and I have to change the line to (according to https://jsonapi.org/format/#fetching-filtering):

        $this->localKey = 'filter[' . Str::singular($this->parent->getEntity()) . '_' . $localKey . ']';