Leff7
2 years ago

Laravel - changing object's field value that is inside of the #appends array

Posted 2 years ago by Leff7

I am trying to change the attributes of an object that I am returning as a json response from the function. This is the piece of code where I do that:

if ($item->post_title == '') {
     $post = $this->findPostId($item);
     $item->post_title = $post->post_title;
     $item->url = $post->guid;
     $item->slug = $post->slug;
     $item->setAttribute('post_id', $post->ID);
} 

I would like to change the value of the slug field as well, but the slug field is inside of the #appends array of the model, and not in the #attributes array. Is there a way to change it for the given object?

Please sign in or create an account to participate in this conversation.