環境:
laravel@8.83.23
jensseger/laravel-mongodb@3.8.0
Model Structure
Profile: {
roles: [’admin’]
}
$profile = App\Profile::find(1);
$profile->roles = array_push($profile->roles, 'superAdmin')
>>> error: Indirect modification of overloaded property App\Profile
solution)
値を編集するのではなく、新たな値を定義する
$roles = array_values($profile->roles)
array_push($roles, 'superAdmin')
$profile->roles = $roles
$profile->save()