title: Laravel 5.6, relationship path is returning array instead of object
body: <p>Longtime googler, first time asker here. Hi, folks.
  I am debugging and updating my app after updating it from Laravel 5.1.10 to 5.6
  and this bug is proving hard to google.</p>
  
  <p>Exploring my error message “Trying to get property of non-object” I think what is happening is that the nested relationship path that used to work just fine to give me the  object, is now instead giving me an array of its attributes.</p>
  
  <p>More code below, but here is the snippet from my view:</p>
  
  <pre><code>@section('content')
  &lt;h2&gt;
  &lt;?php // Header: project number and title ?&gt;
  @if ($bookingDefault-&gt;project-&gt;courseNumber)
      {{ $bookingDefault-&gt;project-&gt;courseNumber }}: 
  @endif
  </code></pre>
  
  <p>This results in error:</p>
  
  <pre><code>Trying to get property 'courseNumber' of non-object 
  </code></pre>
  
  <p>It’s not returning a null; the data is there and it works perfectly fine if I access the project as an array thus:</p>
  
  <pre><code>@section('content')
  &lt;h2&gt;
  &lt;?php // Header: project number and title ?&gt;
  @if ($bookingDefault-&gt;project['courseNumber'])
      {{ $bookingDefault-&gt;project['courseNumber'] }}: 
  @endif
  </code></pre>
  
  <p>So I know that the relationships are defined okay because it is finding the project. It’s just not giving a proper object to the view anymore.
  I could change a large number of views to access attributes as an array instead, but that is a lot of code to comb through and change, and doesn’t give me access to the object’s methods. I would rather fix why I am getting an array instead of the object I was getting before.</p>
  
  <p>CODE THAT MAY BE RELEVANT:</p>
  
  <p>from app/Http/Kernel.php (partial) - I checked that SubstituteBindings::class is there.</p>
  
  <pre><code>/**
   * The application's route middleware groups.
   *
   * @var array
   */
  protected $middlewareGroups = [
      'web' =&gt; [
          \App\Http\Middleware\EncryptCookies::class,
          \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
          \Illuminate\Session\Middleware\StartSession::class,
          \Illuminate\Session\Middleware\AuthenticateSession::class,
          \Illuminate\View\Middleware\ShareErrorsFromSession::class,
          \App\Http\Middleware\VerifyCsrfToken::class,
          \Illuminate\Routing\Middleware\SubstituteBindings::class,
      ],
  
      'api' =&gt; [
          'throttle:60,1',
          'bindings',
      ],
  ];
  
  /**
   * The application's route middleware.
   *
   * These middleware may be assigned to groups or used individually.
   *
   * @var array
   */
  protected $routeMiddleware = [
      'auth' =&gt; \Illuminate\Auth\Middleware\Authenticate::class,
      'auth.basic' =&gt; \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
      'bindings' =&gt; \Illuminate\Routing\Middleware\SubstituteBindings::class,
      'cache.headers' =&gt; \Illuminate\Http\Middleware\SetCacheHeaders::class,
      'can' =&gt; \Illuminate\Auth\Middleware\Authorize::class,
      'guest' =&gt; \App\Http\Middleware\RedirectIfAuthenticated::class,
      'signed' =&gt; \Illuminate\Routing\Middleware\ValidateSignature::class,
      'throttle' =&gt; \Illuminate\Routing\Middleware\ThrottleRequests::class,
  ];
  </code></pre>
  
  <p>from routes/web.php (partial) - all my old Route::model and Route::bind are still there. I wasn’t sure if I was supposed to take them out or put them somewhere else but fiddling with it didn’t change anything. I tried moving them to RouteServiceProvider’s boot() function but that didn’t change anything so I put them back into web.php.</p>
  
  <pre><code>Route::model('bookingdefaults', 'BookingDefault');
  Route::model('bookings',        'Booking');
  Route::model('people',          'User');
  Route::model('projects',        'Project');
  
  Route::bind('bookingdefaults',  function($value, $route) {return App\BookingDefault::where('id', $value)-&gt;first();});
  Route::bind('bookings',         function($value, $route) {return App\Booking::where('id', $value)-&gt;first();});
  Route::bind('people',           function($value, $route) {return App\User::where('id', $value)-&gt;first();});
  Route::bind('projects',         function($value, $route) {return App\Project::where('id', $value)-&gt;first();});
  </code></pre>
  
  <p>In the models - again, not the complete code which is long:</p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class BookingDefault extends Model
  {
      protected $guarded = [];
  
  // RELATIONSHIPS
  
      // always belongs to a certain project
      public function project()
      {
          return $this-&gt;belongsTo('App\Project');
      }
      // always happens a certain place
      public function location()
      {
          return $this-&gt;belongsTo('App\Location');
      }
      // many bookings could be made from this default
      public function bookings()
      {
          return $this-&gt;hasMany('App\Booking');
      }
      // each booking default will suggest several roles that might be filled in a booking
      public function bookingDefaultRoleAssignments()
      {
          return $this-&gt;hasMany('App\BookingDefaultRoleAssignment');
      }
  
      // somtimes it is defining a default of a certain type, but if this is a 
      // customized default then it may not belong to a bookingType
      public function bookingType()
      {
          return $this-&gt;belongsTo('App\BookingType');
      }
  }
  
  &lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  use Mail;
  use App\Booking;
  
  class Project extends Model
  {
       protected $guarded = [];
  
  // RELATIONSHIPS
      public function bookings()
      {
          return $this-&gt;hasMany('App\Booking');
      }
      // a project can have defaults for several types of booking
      public function bookingDefaults()
      {
          return $this-&gt;hasMany('App\BookingDefault');
      }
      // there will be many assignments of users to this project in various roles
      public function projectRoleAssignments()
      {
          return $this-&gt;hasMany('App\ProjectRoleAssignment');
      }
      public function projectType()
      {
          return $this-&gt;belongsTo('App\ProjectType');
      }
  }
  </code></pre>
  
  <p>from BookingDefaultsController.php (partial - actual controller is over 1000 lines)</p>
  
  <p>
  
  <pre><code>namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use App\Http\Requests;
  use App\Http\Controllers\Controller;
  
  use Illuminate\Database\Eloquent\Collection;
  use App\User;
  use App\Booking;
  use App\BookingDefault;
  use App\BookingDefaultRoleAssignment;
  use App\BookingRoleAssignment;
  use App\BookingRole;
  use App\BookingType;
  use App\Location;
  use App\Project;
  use App\Qualification;
  use Illuminate\Support\Facades\DB;
  
  use Input;
  use Redirect;
  use Mail;
  
  class BookingDefaultsController extends Controller
  {
       /**
       * Show the form for editing the specified resource.
       */
      public function edit(BookingDefault $bookingDefault)
      {
          // We'll need all the options for form dropdowns
          $locations = Location::where('status', 'active')-&gt;orderby('location_name')-&gt;get();
          $bookingTypes = BookingType::all();
          $bookingRoles = BookingRole::all();
          $qualifications = Qualification::all();
  
          return view('bookingdefaults.edit', 
              compact('bookingDefault', 'locations', 'bookingTypes', 'bookingRoles', 'qualifications'));
      }
  
  }
  </code></pre>
  
  <p>And finally the view, from /resources/views/bookingdefaults/edit.blade.php</p>
  
  <pre><code>@extends('layout')
  
  @section('title')
      Staffstuff Edit Booking Default
  @stop
  @section('php')
     {{ $user = Auth::user() }}
  @stop
  
  @section('navtag')
     &lt;div id="projpage"&gt;
  @stop
  
  @section('javascript')
  
  @stop
  
  @section('content')
      &lt;h2&gt;
      &lt;?php // Header: project number and title ?&gt;
      @if ($bookingDefault-&gt;project-&gt;courseNumber)
          {{ $bookingDefault-&gt;project-&gt;courseNumber }}: 
      @endif
      @if ($bookingDefault-&gt;project-&gt;shortTitle) {{ $bookingDefault-&gt;project-&gt;shortTitle }} 
          @elseif ($bookingDefault-&gt;project-&gt;title) {{ $bookingDefault-&gt;project-&gt;title }}
      @endif
      &lt;br /&gt;Booking Default:
      &lt;/h2&gt;
      &lt;?php // Form to edit the basic booking info, time, place ?&gt;
      {!! Form::model($bookingDefault, ['method' =&gt; 'PATCH', 'route' =&gt; ['bookingdefaults.update', $bookingDefault-&gt;id]]) !!}
          {!! Form::hidden('id', $bookingDefault-&gt;id) !!}
          {!! Form::hidden('project_id', $bookingDefault-&gt;project_id) !!}
  
          @include('/partials/bookingdefaultform', ['submit_text' =&gt; 'Update Default'])
  
          &lt;div class="form-group"&gt;
              {!! Form::label('update_existing', 'Update existing bookings (see below): ') !!}
              {!! Form::checkbox('update_existing', 'value', TRUE) !!}
              &lt;br /&gt;Note that NOT updating existing bookings will decouple them from this default and they will need to be updated individually.
          &lt;/div&gt;
  
      {!! Form::close() !!}
      &lt;p&gt;
          &lt;a href="{{ route('bookingdefaults.show', $bookingDefault) }}"&gt;DONE EDITING&lt;/a&gt;
      &lt;/p&gt;
  
      @stop
  </code></pre>
  
  <p>The exact error:</p>
  
  <pre><code>ErrorException (E_ERROR)
  Trying to get property 'courseNumber' of non-object (View: /Users/redacted/Sites/testproject032418/resources/views/bookingdefaults/edit.blade.php)
  </code></pre>