title: Laravel soft delete: model::onlyTrashed() returns all
body: <p>When I try to view only soft deleted records in Laravel the onlyTrashed returns all records.</p>
  
  <p>As you will see I also have a searchform which complifies things a bit. And I think the searchform is the reason this doesn't work but I don't understand why excactly.</p>
  
  <p>Controller:</p>
  
  <pre><code>    public function toTrashbin(Request $request) {
          $search = '%' . $request-&gt;input('search') . '%';
          $students = Student::onlyTrashed()
              -&gt;where('first_name', 'like', $search)
              -&gt;orWhere('last_name', 'like', $search)
              -&gt;orWhere('rnumber', 'like', $search)
              -&gt;paginate(15)
              -&gt;appends(['search'=&gt; $request-&gt;input('search')]);
          return view('admin.students.students_trashbin')-&gt;with('students', $students);;
      }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>                    {{--searchform--}}
                      &lt;form method="get" action="/students/trashbin" id="searchForm"&gt;
                          &lt;div class="row"&gt;
                              &lt;div class="col-sm-6 mb-2"&gt;
                                  &lt;input type="text" class="form-control" name="search" id="search"
                                         value="{{request()-&gt;search}}" placeholder="Search by name or R-number"&gt;
                              &lt;/div&gt;
                              &lt;div class="col-sm-2 mb-2"&gt;
                                  &lt;button type="submit" class="btn btn-success btn-block"&gt;Search&lt;/button&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/form&gt;
                      &lt;hr&gt;
  
                  @if (count($students) &gt; 0)
                      {{--table--}}
                      &lt;table class="table"&gt;
                          &lt;thead&gt;
                          &lt;tr&gt;
                              &lt;th scope="col"&gt;Name&lt;/th&gt;
                              &lt;th scope="col"&gt;R-number&lt;/th&gt;
                              &lt;th scope="col"&gt;Deleted at&lt;/th&gt;
                              &lt;th scope="col"&gt;Actions&lt;/th&gt;
                          &lt;/tr&gt;
                          &lt;/thead&gt;
                          &lt;tbody&gt;
                          @foreach ($students as $student)
                              &lt;tr&gt;
                                  &lt;td&gt;{{$student-&gt;first_name}} {{$student-&gt;last_name}}&lt;/td&gt;
                                  &lt;td&gt;{{$student-&gt;rnumber}}&lt;/td&gt;
                                  &lt;td&gt;{{$student-&gt;deleted_at}}&lt;/td&gt;
                                  &lt;td&gt;
                                      &lt;a href="/students/{{$student-&gt;id}}/restore"&gt;restore&lt;/a&gt;
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                          @endforeach
                          &lt;/tbody&gt;
                      &lt;/table&gt;
                      {{$students-&gt;links()}} {{--pagination--}}
                  @else
                      &lt;p&gt;No students found using your searchquery.&lt;/p&gt;
                  @endif
  </code></pre>
  
  <p>Somehow the view displays all students, both soft deleted and not soft deleted ones.</p>
  
  <p>However: It works perfectly if I remove the 3 "where"s in the controller. But then I can't use search obviously. Does anyone know how I can make this work with search?</p>
  
  <p>Thanks.</p>