Indirect Modification of Overloaded Property Laravel MongoDB

Due to how accessing model attributes is implemented in Eloquent, when you access $category->specifics, a magic __get() method is called that returns a copy of that attribute's value. Therefore, when you add an element to that copy, you're just changing the copy, not the original attribute's value. That's why you're getting an error saying that whatever you're doing, it won't have any effect.

If you want to add a new element to $category->specifics array, you need to make sure that the magic __set() is used by accessing the attribute in a setter manner, e.g.:

$category->specifics = array_merge($category->specifics, $this->request->get('specifics'));

You can use this method in case that you want to add a single item to the array:

PHP:

$new_id = "1234567";
$object->array_ids = array_merge($object->array_ids, [$new_id]);

This work's for me!