-
Notifications
You must be signed in to change notification settings - Fork 0
Routing
Filename: app/routes.php
<?php
Route::get('/', function ()
{
return 'Hello world!';
});
// or..
Route::get('/', 'HomeController@index'); <?php
Route::post( .. ); <?php
Route::put( .. ) <?php
Route::delete( .. ) <?php
Route::any( .. );Parameters are segments of url that are dynamic. Any that are defined are passed through to the route action in the order that they appear in the url.
<?php
Route::get('/user/{id}', function ($id)
{
return 'User id: '.$id;
}); <?php
Route::get('/user/{id}, function ()
{
return 'User id: '.$id;
})
->where(array(
'id' => '[0-9]+'
));You may give your routes aliases to make referring to them more convenient.
<?php
Route::get('/', 'HomeController@index')->alias('home');Filters provide a convenient method of limiting access to given routes. a filter to be applied before and after the routing takes place by using the before and after methods.
sums it up
Returning anything from a filter (other than null) will be considered the routes response and halt execution of the rest of the route.
<?php
Route::filter('auth', function ()
{
if (!User::authed())
{
return Redirect::to('home')->now();
}
}); <?php
Route::get( .. )->before('auth'); <?php
Route::get( .. )->after(array('auth', 'locale'));Groups provide a convenient method of applying multiple routes to multiple routes at once.
<?php
Route::group(function ()
{
Route::get( .. );
Route::post( .. );
// and more..
}); <?php
Route::group( .. )
->before('greet')
->after('farewell');You may prefix a group of routes with a segment of the url.
<?php
Route::group(function ()
{
Route::get('/{$country}', function ($country)
{
// http://mysite.com/location/uk
// $country == 'uk'
});
})
->prefix('/location');Hosts provide a special way to filter your routes by hostname, providing powerful ways to have multi-domain sites and dynamic subdomains with wildcard DNS settings.
<?php
Route::group(function ()
{
Route::get('/{$country}', function ($account, $country)
{
// http://aaron.mysite.com/location/uk
// $account == 'aaron'
// $country == 'uk'
});
})
->host('{account}.mysite.com'); <?php
Route::group( .. )
->host('{account}.mysite.com')
->where(array(
'account' => '[A-z]+'
));