Join us on our TWC Discord channel

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Laravel JsonApi
#1
Hi everybody.

I'm currently in an dev internship, and I have to create APIs with php/Laravel/JsonApi.
I use [URL="https://jsonapi.org/"]{json:api}[/URL] and [URL="https://laravel-json-api.readthedocs.io/en/latest/"]https://laravel-json-api.readthedocs.io/en/latest/[/URL]

No problem with php and Laravel, but I'm stuck with JsonApi, with some id name issue !
Problem is, I'm the first in the enterprise to use JsonApi, so none of my colleagues can help me.

I use the [URL="https://jsonapi.org/"]{json:api}[/URL] official manual everyday, and I've tried everything described but can't find a functional solution in-there.
I've asked on Stack Overflow, no response...

Maybe someone knows how to use Laravel and JsonApi, or knows someone who could help...
[Image: 3137_20_11_19_11_03_56.png] [Image: 3137_29_08_20_6_07_21.gif]

[Image: fr.gif] -TWC|LePresident|BMS

[Image: b_560_95_1.png]
Reply
#2
Never used either of these. Can you link the StackOverflow question and/or describe your problem?
I'm quite busy, so unless it's a quick thing or really urgent I am unlikely to be able to answer PMs throughout the week, but I try to reach out to everyone who contacted me during the weekends. If it's urgent, you can also contact any of the supremes, they can do a lot of things or relay directly to me if necessary.
Reply
#3
Hi. Sorry for being so long, I was quite busy.

I found some fixes to my some of my troubles.
But I still have a big issue.

I asked on StackOverflow some questions, like How to use Laravel JSONAPI, which I managed to fix.

Now, basically, I can use the Laravel {json:api} framework, connect to the database, and retrieve any list of records I need (i.e /myurl/myobjects).

But if I try to access a existing record (i.e. /myurl/myobjects/1), I get a 404 error, the id 1 is not found.
Yep, cause we use ID and not id in the database.

So, all I need is to change id to ID.
I searched in the manual, on the net, everything...

Found some stuff like declaring
Code:
$privateKey = 'ID';
or overloading some methods, but for the moment, none of them worked.
[Image: 3137_20_11_19_11_03_56.png] [Image: 3137_29_08_20_6_07_21.gif]

[Image: fr.gif] -TWC|LePresident|BMS

[Image: b_560_95_1.png]
Reply
#4
OK, I went back to my internship after a week of vacation, and found where my error was.

I used artisan to generate an adapter, and I thought it was good, but nope.
artisan generates an empty find() method in the adapter, so ofc, this won't work.

I digged into the Laravel-json-api github, and found how to define the find() method :

Code:
public function find($resourceId) { return $this->findQuery($resourceId)->first(); }

Now, we're talking Smile
[Image: 3137_20_11_19_11_03_56.png] [Image: 3137_29_08_20_6_07_21.gif]

[Image: fr.gif] -TWC|LePresident|BMS

[Image: b_560_95_1.png]
Reply
#5
Glad to hear you got it working. Sorry I didn't get back earlier, we're in release mode at work so I was busy and forgot.
I'm quite busy, so unless it's a quick thing or really urgent I am unlikely to be able to answer PMs throughout the week, but I try to reach out to everyone who contacted me during the weekends. If it's urgent, you can also contact any of the supremes, they can do a lot of things or relay directly to me if necessary.
Reply
#6
Yeah, that was a lot of stress, but, hey, that's part of the game Wink

I hope you enjoy your work as much as I do Smile
[Image: 3137_20_11_19_11_03_56.png] [Image: 3137_29_08_20_6_07_21.gif]

[Image: fr.gif] -TWC|LePresident|BMS

[Image: b_560_95_1.png]
Reply


Forum Jump:


Users browsing this thread: