Issue using for each to loop through an array stored in a variable.

SunnyOjoSunnyOjo Posts: 8
in PHP

I am using laravel framework on this project.

I saved an array of data in a variable,  $this->validate($request, [

            'firstName' => 'required',

            'lastName' => 'required',

            'email' => 'email|required',

            'region' => 'required',

            'province' => 'required',

            'number' => 'required',

            'number_of_children_or_teens' => 'required',

        ]);

        $d = $request->all();

        $setData = $request->session()->put('userdetails', $d);

        return redirect()->route('showData');


here in my controller, I am retrieving it with this,

  $getData = $request->session()->get('userdetails');

//trying to run for each here

        foreach ($getData as $user) {

            echo $user->email;

        }

I get an error that says Trying to get property 'email' of non-object

 if I use dd($getData); I see the data in the variable

Comments

Sign In or Register to comment.