Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indirect modification of overloaded property App\Dossier::$program has no effect

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();

But I receive this Exception http://prntscr.com/j03h0s

Indirect modification of overloaded property App\Dossier::$program has no effect

What have I do to repair this situation?

like image 415
David Avatar asked Apr 03 '18 07:04

David


1 Answers

The problem is that calling $dossier->program does not actually access the property directly in Eloquent type models but rather calls a __get method.

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();
like image 58
apokryfos Avatar answered Nov 04 '22 03:11

apokryfos