Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json output #22

Closed
eMaurits opened this issue Nov 17, 2015 · 10 comments
Closed

Json output #22

eMaurits opened this issue Nov 17, 2015 · 10 comments

Comments

@eMaurits
Copy link

Hi,
I'm using your library for a while now and i really like it. But i have a question about the output of a save action.
If i make a save action i get output that is protected so i can't really use it.
Is there a way to just get the json output from exact so i can use that for more actions?

regards,
Egbert

Ps, i wrote this in english but i am dutch, so if its more convenient to answer in dutch thats possible ;)

@stephangroen
Copy link
Member

Hi @bertjuuhh,

Thank you :) You can assign the new object to a variable by using $item = $item->save(); after which $item is filled with the new data. After that $item->json() will give you a json representation of the object.

Is this enough of the json you need? If not, please let me know what exactly you need from the raw json from Exact.

@eMaurits
Copy link
Author

Hi @stephangroen,

Thats it!!
Thank you very much for the reply :)

Regards
Egbert

@stephangroen
Copy link
Member

Great!

@eMaurits
Copy link
Author

Hi @stephangroen,

is the same trick supposed to work for a the get function as well?
So
$result = $item->get();
$result-json().

regards,
Egbert

@eMaurits eMaurits reopened this Nov 27, 2015
@stephangroen
Copy link
Member

You can always use json() method on an object that extends the Model (so all entities support it).

@eMaurits
Copy link
Author

eMaurits commented Dec 2, 2015

Alright, maybe i'm using it wrong then. Because if I use it like this :
$vatCode = new \Picqer\Financials\Exact\VatCode($connection);
$result = $vatCode->get();
$resultjson = $result->json();

I get the error : Call to a member function json() on a non-object.

I use it the exact same way with the save function.
Regards
Egbert

@stephangroen
Copy link
Member

It seems you are not getting a valid result from $vatCode->get();. You might want to check into that first. var_dump($result).

@eMaurits
Copy link
Author

eMaurits commented Dec 2, 2015

Yeah i have results, i checked it on another function aswell. The same error as result.
The result are filled with a lot of stuff as well, but it starts like this :
[0]=>
object(Picqer\Financials\Exact\VatCode)#38 (5) {
["fillable":protected]=>
array(40) {

I get result now via another way, but thats timeconsuming.

@stephangroen
Copy link
Member

Whoops, I see the problem now. Since you are doing a get call (retrieve all vatcodes), you will get an array of VatCode objects. So $result[0]->json(); will give a JSON representation of the first object in the array.

@eMaurits
Copy link
Author

eMaurits commented Dec 3, 2015

Ah, that explain's it, thank you :)

@eMaurits eMaurits closed this as completed Dec 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants