title: Laravel 6: trying to get property of non-object
body: <blockquote>
    <p>Error: Trying to get property 'gender_id' of non-object </p>
  </blockquote>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>public function printreports(Request $request)
  {
  $id = $request-&gt;get('select2'); //eg. id=1
  $teachers = DB::table('teachers')-&gt;find($id);
  return view('teachers.report1',compact('teachers'));
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>@foreach($teachers as $teacher)
  {{$teacher-&gt;gender_id}}
  @endforeach
  </code></pre>
  
  <p>while if i do it with Eloquent by replacing following query it works, but i want to do it with DB query as stated above.</p>
  
  <pre><code>$teachers = Teacher::find($id);
  </code></pre>