2017-05-03 110 views
0

嗨大家:)我開發的形式,從用戶獲取數據和亞馬遜api搜索然後我想在另一個頁面顯示結果,我只是重定向到另一個頁面與我的結果參數,但我無法訪問我的新頁面參數,這裏是我的代碼laravel 5.2重定向到url參數

  $search = new Search(); 
      $search->setCategory('Books'); 
      $search->setKeywords($searchItem); 
      $search->setPage(2); 
      $search->setResponseGroup(array('Large')); 

      $response = $apaiIO->runOperation($search); 


      $totalResult = $response['Items']['TotalResults']; 
      $totalPage = $response['Items']['TotalPages']; 

      $data = array(
       'response' => $response, 
       'totalResult' => $totalResult, 
       'totalPage' => $totalPage, 
       'uni' => $unies, 
      ); 


      return redirect('/searchItem')->with($data); 

請幫我解決我的問題,謝謝:)

回答

1

如果您在重定向使用with(),您可以訪問$data陣列使用:

{{ session('response') }} 

或:

Session::get('response') 

注意與with()發送的數據是閃存數據,這意味着它會在頁面刷新或導航被刪除。

如果你想添加的數組的網址,你可以這樣做:

redirect('/searchItem?'. http_build_query($data)); 
0

有重定向的方法很多,以葉片的文件或功能。你可以試試這個: -

Redirect to blade file use this method:- 
return view('your viewfile')->with(compact('data')); 
        or 
Redirect to method in controller use this technique:- 
use Illuminate\Support\Facades\Redirect; // Add this in top of controller 
return Redirect::to('/searchItem')->with(compact('data')); 

希望它可以幫助