29.07.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

HTTP Responses 97<br />

the controller since Laravel’s RouteServiceProvider will automatically set the default controller<br />

namespace:<br />

.<br />

1 return redirect()->action('HomeController@index');<br />

Of course, if your controller route requires parameters, you may pass them as the second argument<br />

to the action method:<br />

.<br />

1 return redirect()->action('UserController@profile', [1]);<br />

Redirecting With Flashed Session Data<br />

Redirecting to a new URL and flashing data to the session are typically done at the same time. So,<br />

for convenience, you may create a RedirectResponse instance and flash data to the session in a<br />

single method chain. This is particularly convenient for storing status messages after an action:<br />

.<br />

1 Route::post('user/profile', function () {<br />

2 // Update the user's profile...<br />

3<br />

4 return redirect('dashboard')->with('status', 'Profile updated!');<br />

5 });<br />

Of course, after the user is redirected to a new page, you may retrieve and display the flashed message<br />

from the session. For example, using Blade syntax:<br />

.<br />

1 @if (session('status'))<br />

2 <br />

3 {{ session('status') }}<br />

4 <br />

5 @endif

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!