简体   繁体   中英

Redirect back to previous page with data after search laravel 4.2

i have this search functionanlity in one of my page that when the user clicked search it would go to a controller where it would search a table according to the users input then i would revert it back to the previous page but the records that should be displayed is already based from the search. what i have done so far is the search function and it is already working here it is

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);
}

my problem now is how to redirect it back to the previous page with the data i have searched so far i'am using this

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

but it just redirects to a blank white page. any ideas on how i can do this? thanks so much!

The redirect is after all a response which you are not returning here. To fix that part, simply prepend the missing return statement.

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

Also, remove the dd function since it dumps the variable and then ends further execution of the script. You can use the dump function instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM