title: Facade\Ignition\Exceptions\ViewException Trying to get property 'name' of non-object in index.blade.php
body: <p><strong>I have two tables departments and employees.I want to list departments or employees.The department is okay but when i want to see the employees it gives me this error.I have tried some solutions but it didnt help me ,it still shows this error</strong></p>
  
  <p>this is employees\index.blade.php </p>
  
  <pre><code>----
                  &lt;table class="table"&gt;
                      &lt;tr&gt;
                          &lt;td&gt;Name&lt;/td&gt;
                          &lt;td&gt;Department&lt;/td&gt;
                      &lt;/tr&gt;
                      @foreach($employees as $employee)
                      &lt;tr&gt;
                          &lt;td&gt;{{ $employee-&gt;name }}&lt;/td&gt;
                          &lt;td&gt;{{  $employee-&gt;department-&gt;name }}&lt;/td&gt;
                      &lt;/tr&gt;
                      @endforeach
                  &lt;/table&gt;
  ---
  </code></pre>
  
  <p>this is web.php </p>
  
  <pre><code>Route::get('/', function () {
      return view('welcome');
  });
  
  Auth::routes();
  //Route::get('login/github', 'Auth\LoginController@redirectToGithub');
  //Route::get('login/github/callback', 'Auth\LoginController@handleGithubCallback');
  Route::resource('departments', 'DepartmentsController');
  Route::resource('employees', 'EmployeesController');
  
  Route::get('/home', 'HomeController@index')-&gt;name('home');
  </code></pre>
  
  <p>departments/index.blade.php</p>
  
  <pre><code>...
                  &lt;table class="table"&gt;
                      &lt;tr&gt;
                          &lt;td&gt;Name&lt;/td&gt;
                      &lt;/tr&gt;
                      @foreach($departments as $department)
                      &lt;tr&gt;
                          &lt;td&gt;{{ $department-&gt;name }}&lt;/td&gt;
                      &lt;/tr&gt;
                      @endforeach
                  &lt;/table&gt;
  ...
  
  </code></pre>
  
  <p>EmployeesController</p>
  
  <pre><code>   public function index()
      {
          $employees = \App\Employee::orderBy('id', 'desc')-&gt;paginate(10);
  
          return view('employees.index')-&gt;with('employees', $employees);
      }
  </code></pre>
  
  <p>DepartmentsController</p>
  
  <pre><code>    public function index()
      {
          $departments = \App\Department::all();
          $departments = \App\Department::orderBy('id', 'desc')-&gt;get();
          $departments = \App\Department::orderBy('id', 'desc')-&gt;paginate(5);
          return view('departments.index')-&gt;with('departments', $departments);
      }
  </code></pre>
  
  <p>The error im getting is
  Facade\Ignition\Exceptions\ViewException
  Trying to get property 'name' of non-object (View: C:\xampp\htdocs\Laravel\test2\resources\views\employees\index.blade.php)</p>
  
  <p>If i do   return \App\Employee::orderBy('id', 'desc')->paginate(10); i get this</p>
  
  <pre><code>{"current_page":1,"data":[{"id":2,"name":"Laura","department":""},{"id":1,"name":"Ana","department":""}],"first_page_url":"http:\/\/localhost\/Laravel\/test2\/public\/employees?page=1","from":1,"last_page":1,"last_page_url":"http:\/\/localhost\/Laravel\/test2\/public\/employees?page=1","next_page_url":null,"path":"http:\/\/localhost\/Laravel\/test2\/public\/employees","per_page":10,"prev_page_url":null,"to":2,"total":2}
  </code></pre>