/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Request $request) { $search = \Request::get('search'); //<-- we use global request to get the param of URI $companies = \DB::table('companies')->lists('store_name', 'id'); if ($search) { $allCosts = Cost::whereRaw('date(date_mgr) = ?', [$search])->orderBy('id', 'desc')->paginate(5); } else { $allCosts = Cost::orderBy('id', 'desc')->paginate(5); } return view('cost.index', ['costs' => $allCosts, 'companies' => $companies]); }