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

Can't return response as JSON after saving new model #6

Open
woliveirac opened this issue Jul 13, 2021 · 0 comments
Open

Can't return response as JSON after saving new model #6

woliveirac opened this issue Jul 13, 2021 · 0 comments

Comments

@woliveirac
Copy link

Hello,

I'm using your package and it works fine, however, I've faced an issue after saving a new Model and returning it as JSON.

When your trait update the indexes of the model being saved, something happens that you can't return your model directly into your response as json.

For example:

In my controller on the Store method:

$modelTest = new ModelTest(); // it uses your trait.

$modelTest->title = 'test';
$modelTest->description = 'apsdoj';

$modelTest->save();

return response()->json('modelTest', $modelTest, 201); // here it throws an error saying "Recursion detected".

That's it, to bypass that I've made another select to the model's id created and then I returned it.

Do you have an idea of what can it be?

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant