Craig Johnstone
Craig Johnstone

Reputation: 131

laravel error - Trying to get property of non-object

I'm receiving the Non object error (Trying to get property of non-object) when posting data to my summary view (blade). running dd($data); on the controller returns the payload data correctly (ie flyingFrom, flyingTo)

Form Payload
FlyingFrom
FlyingTo

Controller

 $locations = MyLocations::all()->toJson();
 $data = $request->all();
 return view('summary', compact('data','locations'));

View

@foreach ($data as $locationData)
{{$locationData->flyingFrom}}
{{$locationData->flyingTo}}
@endforeach

Error

Illuminate\Foundation\Bootstrap\HandleExceptions::handleError
resources/views/planner_newsummary.blade.php:28

      <div class="container">

        <div class="col-12">


          <h1 class="ml-2">Book this trip</h1>


            <div class="row">

              <div class="col-sm-6 my-4">


                <div class="card inputcard h-100 progress-step is-complete">

                  <div class="card-header">

                    <i class="fas fa-plane-departure"></i> Flying from

                  </div>

                  <div style="position:relative">



                    <div id="flyingFrom" style="position:relative">{{$locationData->flyingFrom}}</div>

                  </div>

                </div>

              </div>

Upvotes: 0

Views: 501

Answers (1)

Reda Taha
Reda Taha

Reputation: 123

  • just access your data directly
  • $data = $request->all(); returns array
  • in your blade {{$data[flyingFrom]}}

Upvotes: 1

Related Questions