Back

Indirect modification of overloaded property


Johan Johansson posted 3 months ago

I've got an array with child array in it that I'm trying to add a new item to but got this error

Err: "Indirect modification of overloaded property App\Workout::$exercises does not affect."

I am trying with "array_push" and "array_unique" but no luck.

foreach ($workouts as $key => $workout) {
    $workoutHolder[$workout->day_no][] = $workout;
    $workout->exercises = unserialize($workout->exercises);
    $exercise_name = [];

    foreach ($workout->exercises as $k => $exercise) {
        if (!empty($exercise['id']) && !empty($workout->exercises['exercise']['id'])) {
            $get_exercise = Exercise::where('id', $workout->exercises['exercise']['id'])->first();

            if (!empty($workout->exercises['exercise'])) {
                $exercise_name[] = $get_exercise->title;
                $workout->exercises['exercise']['title'] = array_unique($exercise_name);
            }
        }
    }
}

The goal is that the array "$workout->exercises['exercise']" should create a new key "title" and populate it with the response of "$get_exercise."


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us