0

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 ??.

Edited by Samuel_9

3
Contributors
2
Replies
10
Views
1 Year
Discussion Span
Last Post by diafol
1

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');
1

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);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.