Laravel Route for Search -


i try tutorial on laravel live search

but it's on homepage(index)

i want access localhost/laravel/public/search

here controller

class searchcontroller extends controller { public function index() { return view('search.search'); }  public function search(request $request) {    if ($request->ajax())        $output ="";        $orderinfo=db::table('tb_order')->where('shipcustomername','like','%' . $request->search.'%' )                                        ->orwhere('orderid','like','%' .$request->search. '%')->get();     if ($orderinfo)    {         foreach ($orderinfo $key =>$orderinfo ){          $output.='<tr>' .                 '<td>' .$orderinfo->orderid  .'</td>' .                '<td>' .$orderinfo->email  .'</td>' .                '<td>' .$orderinfo->subsource  .'</td>' .                 '</tr>';            }         return response($output);     } 

and route

route::get('/' ,'searchcontroller@index'); route::get('/search' ,'searchcontroller@search'); 

on resources folder have folder search , it's contain search.blade.php

 <div class="container">         <div class="row">         <div class="panel panel-default">             <div class="panel-heading">                 <h3>order info</h3>                            </div>             <div class="panel-body">                 <div class="form-group">                     <input type="text" class="form-control" id="search" name="search"></input>                                  </div>                 <table class="table table-bordered table-hover ">                     <thead>                         <tr>                             <th>orderid</th>                             <th>email</th>                             <th>subsource</th>                         </tr>                     </thead>                     <tbody>                      </tbody>                    </table>                        </div>         </div>     </div>         <script type="text/javascript">             $('#search').on('keyup',function(){                $value=$(this).val();                $.ajax({                    type : 'get',                   url  : '{{url::to('search')}}',                   data : {'search':$value},                   success:function(data){                       $('tbody').html(data);                                      }                 });             });         </script>  </body> 

i know route index ,

 route::get('/' ,'searchcontroller@index'); 

but if try change

 route::get('search' ,'searchcontroller@index'); 

i error 500

what correct way route not use index

thank

there chance sending empty data try change this:

$value=$(this).val(); 

to this:

var value = $('#search').val(); 

if no not submitting data add form:

{{ form::open(array('method'=>'get','class'=> 'col-md-6','url' => '/search', 'id'=>'searchform')) }}  <div class="form-group">    <input type="text" class="form-control" id="search" name="search"></input>                  </div>    {{ form::close() }} 

change ajax request this:

 $('#searchform').on('submit', function(e) {        e.preventdefault();         var search = $('#search').val();        $.ajax({            type: "get",            url: {{url::to('search')}},            data: {search:search}            success:function(data){                       $('tbody').html(data);                                      }        });    }); 

if not then:

set app_debug in .env true since request ajax, using chrome , press f12, go network tab -> click on error -> preview tab, if error blank screen, maybe should chmod 775(write permissions) , try again


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -