Pass an array to Redirect::action in laravel

我是研究僧i 提交于 2020-01-02 20:24:45

问题


I'm trying to pass an array from a function to another function in laravel.

In my PageController.php, I have

public function show($code, $id){
 //some code
  if(isset($search))
   dd($search);
}

and another function

public function search($code, $id){

//some queries 
$result = DB::table('abd')->get();
return Redirect::action('PageController@show, ['search'=>$search]);
}

But this returns me an error like this: ErrorException (E_UNKNOWN) Array to string conversion

I'm using laravel.


回答1:


You could maybe get it to work with passing by the URL by serialization, but I'd rather store it in a session variable. The session class has this nice method called flash which will keep the variable for the next request and then automatically remove it.

Also, and that's just a guess, you probably need to use the index action for that, since show needs the id of a specific resource.

public function search($code, $id){
    //some queries 
    $result = DB::table('abd')->get();
    Session::flash('search', $search); // or rather $result?
    return Redirect::action('PageController@index');
}

public function index($code){
    //some code
    if(Session::has('search')){
        $search = Session::get('search');
        dd($search);
    }
}


来源:https://stackoverflow.com/questions/27716938/pass-an-array-to-redirectaction-in-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!