i'm trying build website laravel , i'm using pagination show result of searching. when click on search button , works when click on next page of pagination ,all values of search form disappear , there no result in searching there help؟
route.php
route::get('search', 'searchcontroller@index');//return search view route::post('misearch', 'searchcontroller@search');// return result route::resource('misearch', 'searchcontroller@search');// pagination
searchcontroller.php
$results = mod_ads::where(function($query){ $ins_brand = input::has('ins_brand')? input::get('ins_brand'):null; $min_price = input::has('min_price')? input::get('min_price'):null; $max_price = input::has('max_price')? input::get('max_price'):null; $ins_color = input::has('ins_color')? input::get('ins_color'):null; if (isset($min_price) && isset($max_price)) { $query -> where('ads_fie_insprice', '>=', $min_price)-> where('ads_fie_insprice', '<=', $max_price); } if ($ins_brand == '0') { unset($ins_brand); }else{ $query->where('ads_fie_insbrand', '=', $ins_brand); } if (isset($ins_color)) { $query->where('ads_fie_inscolor', 'like', '%'.$ins_color.'%'); } })->paginate(2); $link = str_replace('/?', '?', $results->render()); return view::make('search', compact('results', 'link'));
search.blade.php
@if(isset($results)) @foreach($results->getcollection()->all() $result) {{ $result->ads_fie_insbrand }} {{ $result->ads_fie_insprice }} {{ $result->ads_fie_inscolor }} @endforeach @endif @if(isset($results)) {!! $link !!} @endif
anyone can guide me? many many thanks.
here answere
searchcontroller.php
public function search(request $request) { $results = mod_ads::where(function($query){ $ins_brand = input::has('ins_brand')? input::get('ins_brand'):null; $min_price = input::has('min_price')? input::get('min_price'):null; $max_price = input::has('max_price')? input::get('max_price'):null; $ins_color = input::has('ins_color')? input::get('ins_color'):null; if (isset($min_price) && isset($max_price)) { $query -> where('ads_fie_insprice', '>=', $min_price)-> where('ads_fie_insprice', '<=', $max_price); } if ($ins_brand == '0') { unset($ins_brand); }else{ $query->where('ads_fie_insbrand', '=', $ins_brand); } if (isset($ins_color)) { $query->where('ads_fie_inscolor', 'like', '%'.$ins_color.'%'); } })->paginate(2); session::flash('_old_input',input::all()); $link = str_replace('/?', '?', $results->appends($request->input())->render()); return view('search', compact('results', 'link')); }
search.blade.php
@if(isset($results)) @foreach($results->getcollection()->all() $result) {{ $result->ads_fie_brand }} {{ $result->ads_fie_insprice }} {{ $result->ads_fie_inscolor }} @endforeach @endif @if(isset($link)) {!! $link !!}//pagination @endif
Comments
Post a Comment