title: how to display search result in laravel
body: <p>i can not show search result using laravel. below is the code for route, controller and views:</p>
  
  <p>route:</p>
  
  <pre><code>Route::resource('search', 'SearchController');
  </code></pre>
  
  <p>controller:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use App\Order;
  use Redirect;
  use Auth;
  use DB;
  
  class SearchController extends Controller
  {
      public function index(Request $request)
      {
          $order = Order::all();
          return view(search.index', compact(search));
      }
  
      public function search(Request $request)
      {
          $search = $request-&gt;search;
  
          $order = DB::table('order')
              -&gt;where('custName','like',"%".$search."%");
  
          return view('search.index',compact('search'));
      }
  }
  </code></pre>
  
  <p>view</p>
  
  <pre><code>&lt;form action="search" method="GET"&gt;
      &lt;input type="text" name="custName" class="form-control" &lt;br&gt;
                  &lt;button type="submit" class="btn btn-primary"&gt;SEARCH&lt;/button&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;table class="table table-bordered" width="500"&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;font color="white"&gt;RESULT :&lt;/font&gt;&lt;/td&gt;
              &lt;/tr&gt;
              @foreach($order as $order)
              &lt;tr&gt;
                  &lt;td&gt;{{ $order-&gt;custName }}&lt;/td&gt;
                  &lt;td&gt;{{ $order-&gt;orderStatus }}&lt;/td&gt;
              &lt;/tr&gt;
              @endforeach
          &lt;/table&gt;
  </code></pre>
  
  <p>directory location</p>
  
  <pre><code>c:/xampp/htdocs/web/resources/views/search/index.blade.php
  </code></pre>
  
  <p>show error</p>
  
  <pre><code>Undefined variable: order (View: c:\xampp\htdocs\web\resources\views\search\index.blade.php)
  </code></pre>
  
  <p>above is my code to search record in the database. but the result always undefined variable.</p>
  
  <p>how to display the searched result using code above. thank you</p>