iam using laravel 4 ,am trying to pass a variable to a redirect back
return Redirect::back()->with('message','Message has been sent',compact('account','pageTitle'));
like you would have done with a View
return Redirect::back()->with('message','Message has been sent',compact('account','pageTitle'));

is that posssible ??.

Hi, I'm not sure I've understood your request and I haven't used L4 in a while, but:

with('message','Message has been sent',compact('account','pageTitle'))

Should not work, as the with() method accepts only two parameters:

You are feeding three. Instead you could try:

with('message', array('Message has been sent', array('account','pageTitle')))

But I'm not sure it will work, and if it works, you can access it through Session::get('message')[0] and Session::get('message')[1]['account'] or something like that.

So why don't you use Session::flash() before the redirect?

Session::flash('account', 'pageTitle');
Member Avatar for diafol

The compact() method is a the PHP method: http://php.net/manual/en/function.compact.php, which simply makes an array of variables, using the variable names as the keys and variable values as the (yes, you guessed), the values. You can use multiple 'with's:

Redirect::back()->with('message','Message has been sent')->with(compact('account','pageTitle'));

Or even,

Redirect::back()
    ->with('message','Message has been sent')
    ->with('account',$account)
    ->with('pageTitle',$pageTitle);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.