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 77<br />

.<br />

11 *<br />

12 * @param int $photoId<br />

13 * @param int $commentId<br />

14 * @return Response<br />

15 */<br />

16 public function show($photoId, $commentId)<br />

17 {<br />

18 //<br />

19 }<br />

20 }<br />

Supplementing Resource Controllers<br />

If it becomes necessary to add additional routes to a resource controller beyond the default resource<br />

routes, you should define those routes before your call to Route::resource; otherwise, the routes<br />

defined by the resource method may unintentionally take precedence over your supplemental<br />

routes:<br />

.<br />

1 Route::get('photos/popular', 'PhotoController@method');<br />

2<br />

3 Route::resource('photos', 'PhotoController');<br />

Implicit Controllers<br />

Laravel allows you to easily define a single route to handle every action in a controller class.<br />

First, define the route using the Route::controller method. The controller method accepts two<br />

arguments. The first is the base URI the controller handles, while the second is the class name of the<br />

controller:<br />

.<br />

1 Route::controller('users', 'UserController');<br />

Next, just add methods to your controller. The method names should begin with the HTTP verb<br />

they respond to followed by the title case version of the URI:

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

Saved successfully!

Ooh no, something went wrong!