nilportugues / laravel5-jsonapi

Laravel 5 JSON API Transformer Package
http://nilportugues.com
MIT License
311 stars 70 forks source link

Lumen installation throws action() exception #42

Open OskarD opened 8 years ago

OskarD commented 8 years ago

I am trying to implement this with a Lumen application, and I get the following exception:

"exception": {
      "type": "FatalThrowableError",
      "file": "JsonApiTrait.php",
      "line": 74,
      "message": "Fatal error: Call to undefined function NilPortugues\Laravel5\JsonApi\Controller\action()"
    }

Am I missing something or are there compatibility problems?

JsonApiTrait uses the action() helper, which is unavailable with Lumen.

OskarD commented 8 years ago

I think something went wrong in my set-up. I re-did everything and didn't get this error anymore.

I am getting this, however: "status": 400, "title": "Bad Request", "detail": "Request could not be served."

Not much to go by here... Any tips?

nilportugues commented 8 years ago

Hmm go to the NilPortugues\Laravel5\JsonApi\Controller\JsonApiTrait and go to the exception bit matching your action and do a print_r or a $e->getMessage.

You'll get the info there.

I've been already requested to add a dev flag to let these errors go up, instead of catching them. But haven't had time to add the feature yet.

OskarD commented 8 years ago

I am getting the first error again... It's because JsonApiTrait uses the action() helper on line 74. Is it supposed to do this?

I change it to this and I get the second error instead (Which also appears on the show-page): $uri = route('myresource.index'); // action($controllerAction, []);

Edit: It turns out the second error is caused by this: Undefined index: App\Party\Property\Property. It's probably specific to my other code, so I will figure it out myself. But the above problem still remains!

nilportugues commented 8 years ago

@OskarD did you solve this? I'm actually curious what was making it happen... so maybe I can add a defensive check.

OskarD commented 8 years ago

@nilportugues no, it's still happening.

Why is it calling the action() helper-function? Is it supposed to happen? It isn't featured in Lumen

OskarD commented 8 years ago

@nilportugues the action() function is not available in Lumen, it shouldn't be called in JsonApiTrait (Line 74) if using Lumen, should it?

nilportugues commented 8 years ago

https://github.com/nilportugues/laravel5-jsonapi/releases/tag/2.1.11

Try updating your composer dependency to use release 2.1.11.

OskarD commented 8 years ago

Thank you @nilportugues for helping out, but I'm afraid it isn't enough

$absolute in the action arguments needs to be defaulted to true for the code to run without a Missing argument 3 error, and after fixing that I get this error instead: Fatal error: Call to undefined method Laravel\Lumen\Routing\UrlGenerator::action()

I don't think Lumen offers the action functionality at all :/

nilportugues commented 8 years ago

I'll have to hack it better. Not at home right now. Sorry is taking so long.

OskarD commented 8 years ago

It's OK, I am very glad you are willing to help :)

OskarD commented 8 years ago

@nilportugues have you had the chance to take a look at this yet?

nilportugues commented 8 years ago

Starting tomorrow evening I'll be capable to look into it. Been quite busy lately

OskarD commented 8 years ago

Any news @nilportugues?