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 Controllers 74<br />

.<br />

1 $url = action('FooController@method');<br />

You may also use the route helper to generate a URL to a named controller route:<br />

.<br />

1 $url = route('name');<br />

Controller Middleware<br />

Middleware may be assigned to the controller’s routes like so:<br />

.<br />

1 Route::get('profile', [<br />

2 'middleware' => 'auth',<br />

3 'uses' => 'UserController@showProfile'<br />

4 ]);<br />

However, it is more convenient to specify middleware within your controller’s constructor. Using<br />

the middleware method from your controller’s constructor, you may easily assign middleware to<br />

the controller. You may even restrict the middleware to only certain methods on the controller class:<br />

.<br />

1 class UserController extends Controller<br />

2 {<br />

3 /**<br />

4 * Instantiate a new UserController instance.<br />

5 *<br />

6 * @return void<br />

7 */<br />

8 public function __construct()<br />

9 {<br />

10 $this->middleware('auth');<br />

11<br />

12 $this->middleware('log', ['only' => ['fooAction', 'barAction']]);<br />

13<br />

14 $this->middleware('subscribed', ['except' => ['fooAction', 'barAction']]\<br />

15 );<br />

16 }

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

Saved successfully!

Ooh no, something went wrong!