如何在搜索后使用GET和拉拉维尔清理网址?

我正在使用GET方法来搜索数据库中的一些记录


<form id="cliente" class="form-horizontal" action="{{route('resultados_clientes')}}" method="get">

        <div class="form-group row">

          <label class="col-md-6 col-form-label" for="cliente"></label>

          <div class="col-md-12">

            <input form="cliente" maxlength="100" autocomplete="off" class="form-control" id="cliente" type="text" name="cliente" placeholder="Introduzca el rif o nombre del cliente a buscar" required>

            <br>

            <div class="pull-right">

            <button form="cliente" class="btn btn-sm btn-info" type="submit">

              Buscar</button>

          </div>

        </div>

      </form>

问题是,当我找到一些东西并且我返回我的页面进行搜索时,它会在URL中返回搜索的参数...我想清理一下。我该怎么办?


这是我的控制器的功能


public function resultados_clientes(Request $request){

  $busqueda = $request->cliente;

  $clientes = strtoupper($busqueda);

  $perimetro = DB::table('tbl_perimetros as a')

    ->select('a.id','a.rif','a.cod_cliente','a.razon_social','a.holdings_id')

    ->leftjoin('tbl_holdings as b','b.id','=','a.holdings_id')

    ->select(array('a.id','b.hrif','b.hrazon_social','a.rif','a.razon_social','a.estatus'))

    ->where('a.rif','like', '%' . $clientes . '%')

    ->orWhere('a.razon_social', 'like', '%' . $clientes . '%')

    ->orWhere('b.hrif', 'like', '%' . $clientes . '%')

    ->orWhere('b.hrazon_social', 'like', '%' . $clientes . '%')  

    ->get();


  if($perimetro->count()) {

    return view('Busqueda_est.resultados_clientes',compact('perimetro','busqueda'));

  }


  $error_code = 1;

   return view('Busqueda_est.index', compact('error_code'));


}

我想在.blade中做一种函数或类似的东西,也许用javascript或php


这是我的.网站


/*BUSQUEDA ESTANDAR*/

Route::namespace('Busquedaest')->group(function () {

Route::get('busqueda_est', 'BusquedaestController@index')->name('busqueda_est');

Route::get('busqueda_est-resultados-clientes', 'BusquedaestController@resultados_clientes')->name('resultados_clientes');

});


慕沐林林
浏览 149回答 3
3回答

慕娘9325324

您需要使用 POST 而不是 GET。为此,请将您的 html 表单更改为:<form id="cliente" class="form-horizontal" action="{{route('resultados_clientes')}}" method="post">&nbsp; &nbsp; @csrf&nbsp; &nbsp; <div class="form-group row">&nbsp; &nbsp; &nbsp; <label class="col-md-6 col-form-label" for="cliente"></label>&nbsp; &nbsp; &nbsp; <div class="col-md-12">&nbsp; &nbsp; &nbsp; &nbsp; <input form="cliente" maxlength="100" autocomplete="off" class="form-control" id="cliente" type="text" name="cliente" placeholder="Introduzca el rif o nombre del cliente a buscar" required>&nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; <div class="pull-right">&nbsp; &nbsp; &nbsp; &nbsp; <button form="cliente" class="btn btn-sm btn-info" type="submit">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Buscar</button>&nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; </div>&nbsp; </form>在您的网络中.php替换:Route::get('busqueda_est-resultados-clientes', 'BusquedaestController@resultados_clientes')->name('resultados_clientes');跟:Route::post('busqueda_est-resultados-clientes', 'BusquedaestController@resultados_clientes')->name('resultados_clientes');

慕雪6442864

你可以做的是对服务器进行ajax调用以获取所有记录。使用方法会起作用,但它会导致每次您想在某些浏览器中重新加载页面时弹出对话框。POST根据您是否正在使用任何 JavaScript 框架,有不同的方法可以实现此目的。我最喜欢的框架是VueJs,我实际上将在本周五流式传输有关如何构建搜索组件的截屏视频 - 欢迎您加入:https://youtu.be/FJ1MaNtjPDs使用(甚至是直接的 JavaScript),您可以使用公理调用,它看起来像这样:VueJsaxios.get('/your-end-point-here')&nbsp; .then(function (response) {&nbsp; &nbsp; &nbsp; // use response.data with the returned data for the list&nbsp; })&nbsp; .catch(function (error) {&nbsp; &nbsp; &nbsp; console.log(error);&nbsp; })

慕仙森

如果您使用的是 GET 方法,则 URL 上将具有参数。为了使它们不可见,您应该改用POST方法。
打开App,查看更多内容
随时随地看视频慕课网APP