Get current URL
You can obtain the current URL in either of the following ways,URL::current()
OrURL::full()
The difference is that the get parameter is not returned, as shown in figure
Route::get(‘/current/url‘,function()
{
return URL::current();
});
Input/current/url?foo=bar
Only showhttp://myapp.dev/current/url
. UseURL::full()
Displayhttp://myapp.dev/current/url?foo=bar
Obtain the previous URL
// app/routes.php
Route::get(‘first‘,function()
{
// Redirect to the second route.
return Redirect::to(‘second‘);
});
Route::get(‘second‘,function()
{
eturn URL::previous();
});
Input/first
, Returnhttp://loacahost
,URL::previous()
The returned route is the previous route to first.
Generate URL
UseURL::to()
Generate a URL, as shown in figure
Route::get(‘example‘,function()
{
return URL::to(‘another/route‘, array(‘foo‘,‘bar‘));
});
The generated URL ishttp://myapp.dev/another/route/foo/bar
To change the HTTP protocol to https, use
URL::to(‘another/route‘, array(‘foo‘,‘bar‘),true);
Or use
URL::secure(‘another/route‘, array(‘foo‘,‘bar‘));
Use route alias to generate URL
Route::get(‘the/best/avenger‘, array(‘as‘=>‘ironman‘,function()
{
return‘Tony Stark‘;
}));
Route::get(‘example‘,function()
{
return URL::route(‘ironman‘);
});
Use URL parameters
Route::get(‘the/{first}/avenger/{second}‘, array(
‘as‘=>‘ironman‘,
function($first, $second){
return"Tony Stark, the {$first} avenger {$second}.";
}
));
Route::get(‘example‘,function()
{
return URL::route(‘ironman‘, array(‘best‘,‘ever‘));
});
URL to the Controller
// Route to the Stark controller.
Route::get(‘tony/the/{first}/genius‘,‘[email protected]‘);
Route::get(‘example‘,function()
{
return URL::action(‘[email protected]‘, array(‘narcissist‘));
});
Absolute URL to resource
Route::get(‘example‘,function()
{
return URL::asset(‘img/logo.png‘);
});
Returnhttp://myapp.dev/img/logo.png
, Similarly, Use https
return URL::asset(‘img/logo.png‘,true);
Or
return URL::secureAsset(‘img/logo.png‘);
Generate URL in view
Useurl()
Generate a URL in the view. The method and parameters are similar to the preceding one.
<ahref="">My Route</a>
Or
<ahref="">My Route</a>
Use route alias
<ahref="">My Route</a>
Use Controller
<ahref="">My Route</a>
Use resources
<ahref="">My Route</a>
<ahref="">My Route</a>
End
For URL information, see the API on the official website.
From: http://www.cnblogs.com/steven9801/p/3560738.html
More: http://codego.net/573717/
Laravel URL management and usage