title: Trying to get property 'name' of non-object - Laravel
body: <p>I want to implement a search option  for some data in my Laravel app, but I have some problems with this:</p>
  
  <pre><code>public function index()
  {
  
       $students= Student::all(); // When I use this form it appear all of Students even I put a name in Search option
       $students= new Student;//When I use this form I have this error: Trying to get property 'name' of non-object ...
  
      if (request()-&gt;filled('name')) {
  
         $students-&gt;where('name', '=', request()-&gt;input('name'));         
     }
      else{
             $students=Student::all();
      }
      return view('students.index',['students'=&gt;$students]);
  }
  </code></pre>
  
  <p>And my view is:</p>
  
  <pre><code> &lt;form action="{{action('StudentController@index')}}" class="d-flex w-100"&gt;
                  &lt;div class="col-4 p-0"&gt;
                      &lt;input class="form-control" type="text" name="name" id="name" placeholder="name"&gt;
                  &lt;/div&gt;
   &lt;/form&gt;
  </code></pre>
  
  <p>When I try to display students' names, I get the error "Trying to get property 'name' of non-object"</p>