user1012181
user1012181

Reputation: 8726

Pass an array to Redirect::action in laravel

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.

Upvotes: 1

Views: 2116

Answers (1)

lukasgeiter
lukasgeiter

Reputation: 153020

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

Upvotes: 3

Related Questions