Problem retrieving values from imported array

Published 10 months ago by JokersMild85

I'm receiving an error when I try to output some values from an array. The error I'm receiving is "Trying to get property of non-object". Can someone take a look at my code and see what I'm doing wrong?

Controller method:

public function step(Request $request)
    $values = $request->input('exercise');
        $array = explode("-", $values[$i]);
        $exercises[$i]['exercise_id'] = $array[0];
        $exercises[$i]['exercise_type_id'] = $array[1];
        $exercises[$i]['exercise_name'] = $array[2];

    return view('workouts.step', compact('exercises'));

Code from the view:

@foreach($exercises as $exercise)

{!! Form::label('exercise_name', $exercise->exercise_name) !!}


Right now I'm just trying to get output from one of the array keys , exercise_name.


You are trying to access $exercises as an object, when in fact it is an array. Instead, use $exercise['excersize_name'] within the view

{!! Form::label('exercise_name', $exercise['exercise_name']) !!}

Please sign in or create an account to participate in this conversation.