title: How To Implement Simple CRUD Search in Laravel?
body: <p>I have a table that contains data and I want to implement a search feature to it. Example, I would type a query in the search bar and it would look through similar terms in the table columns and then display the rows that contain matches.</p>
  
  <p>This is the error I keep coming across.</p>
  
  <p><a href="https://i.stack.imgur.com/07LIl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/07LIl.png" alt="enter image description here"></a></p>
  
  <p>I just followed <a href="https://www.youtube.com/watch?v=KWnmOBkHzUo" rel="nofollow noreferrer">this</a> tutorial and used my variables instead. I don't know what I'm doing wrong. I did everything according to it.</p>
  
  <p>Here is my TicketController code:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use App\Ticket;
  use Illuminate\Http\Request;
  use App\Http\Requests\TicketUpdateRequest;
  
  class TicketController extends Controller
  {
      /**
       * Display a listing of the resource.
       *
       * @return \Illuminate\Http\Response
       */
      public function index()
      {   
          $tickets= Ticket::latest()-&gt;paginate(10);
          return view('tickets.index', compact('tickets'));
      }
  
      /**
       * Show the form for creating a new resource.
       *
       * @return \Illuminate\Http\Response
       */
      public function create()
      {
          return view('tickets.create');
      }
  
      public function delete(Ticket $ticket)
      {
          return view('tickets.delete', ['tickets' =&gt; $tickets]);
      }
  
      /**
       * Store a newly created resource in storage.
       *
       * @param  \Illuminate\Http\Request  $request
       * @return \Illuminate\Http\Response
       */
      public function store(Request $request)
      {
          Ticket::create([
          'summary'=&gt;request('summary'),
          'description'=&gt;request('description'),
          'status'=&gt;request('status'),
          'updated_at'=&gt;request('updated_at'),
          'name_client'=&gt;request('name_client'),
          'contactnum'=&gt;request('contactnum'),
          'location'=&gt;request('location'),
          'rtype'=&gt;request('rtype'),
          'personnel'=&gt;request('personnel'),
          'priority'=&gt;request('priority'),
          'notes'=&gt;request('notes'),
          ]);
  
          return redirect()-&gt;route('tickets.index');
      }
  
      /**
       * Display the specified resource.
       *
       * @param  \App\Ticket  $ticket
       * @return \Illuminate\Http\Response
       */
      public function show(Ticket $ticket)
      {
          return view('tickets.show', compact('ticket'));
      }
  
  
      public function search(Request $request)
      {
          $search = $request-&gt;get('search');
          $tickets = Ticket::latest('tickets')-&gt;orWhere('rtype', 'like', '%'.$search.'%')-&gt;paginate(10);
          return view('tickets.index',['tickets' =&gt; $tickets]);
      }
  
  
  
      /**
       * Show the form for editing the specified resource.
       *
       * @param  \App\Ticket  $ticket
       * @return \Illuminate\Http\Response
       */
      public function edit(Ticket $ticket)
      {
          //
      }
  
      /**
       * Update the specified resource in storage.
       *
       * @param  \Illuminate\Http\Request  $request
       * @param  \App\Ticket  $ticket
       * @return \Illuminate\Http\Response
       */
      public function update(TicketUpdateRequest $request, Ticket $ticket)
      {
  
          $ticket-&gt;summary = request('summary');
          $ticket-&gt;description = request('description');
          $ticket-&gt;status = request('status');
          $ticket-&gt;name_client= request('name_client');
          $ticket-&gt;contactnum= request('contactnum');
          $ticket-&gt;location= request('location');
          $ticket-&gt;rtype= request('rtype');
          $ticket-&gt;personnel= request('personnel');
          $ticket-&gt;priority= request('priority');
          $ticket-&gt;notes= request('notes');
          $ticket-&gt;save();
  
  
  
          return redirect()-&gt;route('tickets.index');
      }
  
      /**
       * Remove the specified resource from storage.
       *
       * @param  \App\Ticket  $ticket
       * @return \Illuminate\Http\Response
       */
      public function destroy(Ticket $ticket)
      {
          $ticket-&gt;delete();
          return redirect()-&gt;route('tickets.index');
      }
  }
  </code></pre>
  
  <p>and the search part of my navbar:</p>
  
  <pre><code>&lt;form action="/search" method="get"&gt;
    &lt;input class="form-control form-control-dark w-100" type="search" placeholder="Search" aria-label="Search"&gt;&lt;/form&gt;
  </code></pre>
  
  <p>Here is also the table part of my index page:</p>
  
  <pre><code>&lt;table class="table table-striped table-sm"&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;Ticket&lt;/th&gt;
        &lt;th&gt;Last Updated&lt;/th&gt;
        &lt;th&gt;Subject&lt;/th&gt;
        &lt;th&gt;Request Type&lt;/th&gt;
        &lt;th&gt;Request Details&lt;/th&gt;
        &lt;th&gt;Notes&lt;/th&gt;
        &lt;th&gt;Priority&lt;/th&gt;
        &lt;th&gt;Status&lt;/th&gt;
        &lt;th&gt;Actions&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      @foreach($tickets as $ticket)
      &lt;tr&gt;
        &lt;td&gt;{{$ticket-&gt;id}}&lt;/td&gt;
        &lt;td&gt;{{$ticket-&gt;updated_at}}&lt;/td&gt;
        &lt;td&gt;{{$ticket-&gt;summary}}&lt;/td&gt;
        &lt;td&gt;{{$ticket-&gt;rtype}}&lt;/td&gt;
        &lt;td&gt;{{str_limit($ticket-&gt;description, 40)}}&lt;/td&gt;
        &lt;td&gt;{{str_limit($ticket-&gt;notes, 40)}}&lt;/td&gt;
        &lt;td&gt;{{$ticket-&gt;priority}}&lt;/td&gt;
        &lt;td&gt;{{$ticket-&gt;status}}&lt;/td&gt;
        &lt;td&gt;&lt;a href="/tickets/{{$ticket-&gt;id}}" class="btn btn-primary"&gt;Update&lt;/a&gt;
            &lt;a href="/tickets/delete/{{$ticket-&gt;id}}" class="btn btn-danger"&gt;Delete&lt;/a&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
      @endforeach
    &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>and lastly my routes:</p>
  
  <pre><code>&lt;?php
  
  
  Route::get('/', function () {
      return view('welcome');
  });
  
  Route::get('/tickets', 'TicketController@index')-&gt;name('tickets.index')-&gt;middleware('auth');
  
  Route::get('/tickets/create','TicketController@create')-&gt;name('tickets.create')-&gt;middleware('auth');
  
  Route::post('/tickets/create','TicketController@store')-&gt;name('tickets.store')-&gt;middleware('auth');
  
  Route::post('/tickets/{ticket}','TicketController@update')-&gt;name('tickets.update')-&gt;middleware('auth');
  
  Route::get('/tickets/delete/{ticket}','TicketController@delete')-&gt;name('tickets.delete')-&gt;middleware('auth');
  
  Route::post('/tickets/delete/{ticket}','TicketController@destroy')-&gt;name('tickets.destroy')-&gt;middleware('auth');
  
  
  Route::get('/tickets/{ticket}','TicketController@show')-&gt;name('tickets.show')-&gt;middleware('auth');
  
  
  
  Route::get('/', 'TicketController@index');
  Route::get('/search','TicketController@search');
  Route::resource('tickets','TicketController');
  
  Route::get('/clientrequest','ClientRequestController@create')-&gt;name('clientrequest');
  
  Route::post('/clientrequest','ClientRequestController@store')-&gt;name('clientrequest');
  
  
  Auth::routes();
  
  Route::get('/home', 'HomeController@index')-&gt;name('home');
  
  Route::get('/logout', 'Auth\LoginController@logout');
  
  Route::get('admin/routes', 'HomeController@admin')-&gt;middleware('admin');
  </code></pre>
  
  <p>EDIT: This is my model:</p>
  
  <p><a href="https://i.stack.imgur.com/if9FJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/if9FJ.png" alt="enter image description here"></a></p>