php - Is there any better way to fill form input values in the above search form? -


i have search form below 1 field

{!! form::open(array('method' => 'post',          'action' => 'customercontroller@searchcustomers',          'class' => "form-horizontal form-label-left")) !!}     {!! csrf_field() !!}         <input type="text" class="form-control" name="customer">         <button type="submit">search</button> {!! form::close() !!} 

below code in controller

$allcustomers = \app\models\customer_model     ::where('customer', 'like', '%'.$customer.'%')     ->get(); return view('customer.list', array('allcustomers' => $allcustomers)); 

what trying ?

when form submitted search, in view , should able view keyword again in textbox. doing below.

return view('customer.list', array('allcustomers' => $allcustomers, 'key' => $customer)); 

and in form, doing below.

<input type="text" class="form-control" name="customer" value="{{$key}}"> 

question

is there better way fill form input values in above search form ?

i think correct approach checking if key present in request using input inline check $request->input('key', null), if return null, else return key, check code bellow.

controller :

public function index(request $request) {     $key = $request->input('key', null);      $allcustomers = \app\models\customer_model         ::where('customer', 'like', '%'.$customer.'%')->get();      return view('customer.list', compact('allcustomers', 'key')); } 

view :

<input type="text" class="form-control" name="customer" value="{{is_null($key)?'':$key}}"> 

hope helps.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -