间接修改重载属性App \ Dossier :: $ program无效 [英] Indirect modification of overloaded property App\Dossier::$program has no effect
问题描述
早上好,我在后端有此代码(尝试在MONGO中更新此值) http://prntscr.com/j03gh4
Good Day I have this code on backend (trying to update this value in MONGO) http://prntscr.com/j03gh4
$dossier=Dossier::where('_id',(int)$request->input('dossier_id'))->first();
//var_dump($request->input('value'));
$dossier->program[$request->input('program')]['cities']
[$request->input('city')]['services']
[$request->input('service')][$request->input('name')]=$request->input('value');
$dossier->save();
但我收到此异常 http://prntscr.com/j03h0s
对重载属性App \ Dossier :: $ program的间接修改无效
Indirect modification of overloaded property App\Dossier::$program has no effect
该如何解决这种情况?
推荐答案
问题是,调用$dossier->program
并没有直接在Eloquent类型模型中直接访问该属性,而是调用了__get
方法.
The problem is that calling $dossier->program
does not actually access the property directly in Eloquent type models but rather calls a __get
method.
该get方法不会返回对该属性的引用.您应该做的就是获取原始属性,对其进行修改,然后放回原处:
That get method does not return a reference to the property. What you should do is grab the original property, modify it and then put it back:
$dossier=Dossier::where('_id',(int)$request->input('dossier_id'))->first();
$originalProgram = $dossier->program;
$originalProgram[$request->input('program')]['cities'][$request->input('city')]['services'][$request->input('service')][$request->input('name')]=$request->input('value');
$dossier->program = $originalProgram;
$dossier->save();
这篇关于间接修改重载属性App \ Dossier :: $ program无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!