📜  间接修改重载属性没有影响 laravel - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:52.083000             🧑  作者: Mango

代码示例1
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 attributes value. Therefore, when you add an element to that copy,
you are just changing the copy, not the original attributes 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'));