Skip to content

Commit

Permalink
document implicit controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jun 7, 2015
1 parent b3c24be commit 177fba4
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [Naming Resource Routes](#restful-naming-resource-routes)
- [Nested Resources](#restful-nested-resources)
- [Supplementing Resource Controllers](#restful-supplementing-resource-controllers)
- [Implicit Controllers](#implicit-controllers)
- [Dependency Injection & Controllers](#dependency-injection-and-controllers)
- [Route Caching](#route-caching)

Expand Down Expand Up @@ -176,6 +177,62 @@ If it becomes necessary to add additional routes to a resource controller beyond

Route::resource('photos', 'PhotoController');

<a name="implicit-controllers"></a>
## Implicit Controllers

Laravel allows you to easily define a single route to handle every action in a controller class. First, define the route using the `Route::controller` method. The `controller` method accepts two arguments. The first is the base URI the controller handles, while the second is the class name of the controller:

Route::controller('users', 'UserController');

Next, just add methods to your controller. The method names should begin with the HTTP verb they respond to followed by the title case version of the URI:

<?php namespace App\Http\Controllers;

class UserController extends Controller
{
/**
* Responds to requests to GET /users
*/
public function getIndex()
{
//
}

/**
* Responds to requests to GET /users/show/1
*/
public function getShow($id)
{
//
}

/**
* Responds to requests to GET /users/admin-profile
*/
public function getAdminProfile()
{
//
}

/**
* Responds to requests to POST /users/profile
*/
public function postProfile()
{
//
}
}

As you can see in the example above, `index` methods will respond to the root URI handled by the controller, which, in this case, is `users`.

#### Assigning Route Names

If you would like to [name](/docs/{{version}}/routing#named-routes) some of the routes on the controller, you may pass an array of names as the third argument to the `controller` method:

Route::controller('users', 'UserController', [
'getShow' => 'user.show',
]);

<a name="dependency-injection-and-controllers"></a>
## Dependency Injection & Controllers

Expand Down

0 comments on commit 177fba4

Please sign in to comment.