Skip to content

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

@woliveirac

Description

@woliveirac

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions