在搜索laravel 4.2之后,使用数据重定向回上一页

时间:2016-07-13 03:01:50

标签: laravel laravel-4

我在我的一个页面中有这个搜索功能,当用户点击搜索它会转到控制器,它会根据用户输入搜索一个表然后我会将它恢复到上一页但是记录应该显示已经基于搜索。到目前为止我所做的是搜索功能,它已经在这里工作了

function ajaxCall() {
    let url = 'https://maps.googleapis.com/maps/api/geocode/json?address=london';
    return new Promise((resolve, reject) => {
      let xmlhttp = new XMLHttpRequest();
      xmlhttp.onreadystatechange = () => {
        if (xmlhttp.readyState == XMLHttpRequest.DONE) {
          if (xmlhttp.status == 200) {
            // resolve instead of return inside of a Promise closure
            resolve(JSON.parse(xmlhttp.response));
          } else {
            // reject instead of throw
            // (will throw the error at the `await` expression.)
            reject(Error(`Received status code ${xmlhttp.status}`));
          }
        }
    }
    xmlhttp.open('GET', url, true);
    xmlhttp.send();
  });
}

我现在的问题是如何使用我搜索到的数据将其重定向回上一页我使用此

public function tsearch()
{
    $rnme = Input::get('rname');
    $ath  = Input::get('auth');
    $fsze = Input::get('fsize');
    $ftyp = Input::get('ftype');
    $dc = Input::get('dcreate');
    $du = Input::get('dupload');
    $wld = Input::get('wldcrd');

    $sbar = Input::get('searchb');
    // dd($sbar);

    // dd($sbar , $rnme , $ath , $fsze , $ftyp , $dc , $du, $wld);
    $subcatid = Session::get('SCid');

    $NSAdata = DB::table('nsa_fileuploads AS fu')
            ->join('nsa_systemusers AS nsu' , 'fu.sid' , '=' , 'nsu.sid')
            ->join('nsa_subcategory AS sc' , 'fu.subcategoryid' , '=' , 'sc.subcategoryid')
            ->join('nsa_maincategory AS mc' , 'sc.maincategoryid' , '=' , 'mc.maincategoryid')
            ->select('fu.fileid' , 'fu.filename' , 'fu.filesize' , 'fu.filetype',
                     'fu.thumbnail' , 'fu.confidential' , 'fu.sid', 'nsu.username',
                     'sc.subcategoryname', 'fu.updated_at' , 'fu.created_at', 'mc.maincategoryname' , 'sc.subcategoryid' )
            ->where('fu.subcategoryid' , '=' , $subcatid);

    $tick = "";

    if($rnme == 'true')
    {
        $tick = $tick . " rname";
        $NSAdata = $NSAdata->where('fu.filename' , 'LIKE' , '%'.$sbar.'%');
    }
    if($ath == 'true')
    {
        $tick = $tick . " auth";
        $NSAdata = $NSAdata->where('nsu.username' , 'LIKE' , '%'.$sbar.'%');
    }
    if($fsze == 'true')
    {
        $tick = $tick . " fsze";
        $NSAdata = $NSAdata->where('fu.filesize' , 'LIKE' , '%'.$sbar.'%');
    }
    if($ftyp == 'true')
    {
        $tick = $tick . " ftyp";
        $NSAdata = $NSAdata->where('fu.filetype' , 'LIKE' , '%'.$sbar.'%');
    }
    if($dc == 'true')
    {
        $tick = $tick . " dc";
        $NSAdata = $NSAdata->where('fu.created_at' , 'LIKE' , '%'.$sbar.'%');
    }
    if($du == 'true')
    {
        $tick = $tick . " du";
        $NSAdata = $NSAdata->where('fu.updated_at' , 'LIKE' , '%'.$sbar.'%');
    }
    if($wld == 'true')
    {
        $tick = $tick . " wld";
        $NSAdata = $NSAdata->where('fu.wildcard' , 'LIKE' , '%'.$sbar.'%');
    }

    $NSAdata = $NSAdata->get();

    dd($NSAdata);

    Redirect::back()->with('NSAdata' , $NSAdata);
}

但它只是重定向到空白页面。关于我如何做到这一点的任何想法?非常感谢!

1 个答案:

答案 0 :(得分:0)

重定向是一个你没有返回的响应。要修复该部分,只需添加缺少的return语句。

return Redirect::back()->with('NSAdata' , $NSAdata);

此外,删除dd函数,因为它转储变量,然后结束脚本的进一步执行。您可以改为使用dump功能。