Skip to content
Discussion options

You must be logged in to vote

You can change the representation of the model to rename id to _id by overriding the toArray method of your model class:

class Invoice
{
    // ...

    public function toArray()
    {
        $values = parent::toArray();
        if (array_key_exists('id', $values)) {
            $values['_id'] = $values['id'];
            unset($values['id']);
        }
        
        return $values;
    }
}

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by jmikola

This comment was marked as disruptive content.

@GromNaN
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #3240 on January 07, 2025 13:41.