使用路由别名生成URL
Route::get(‘the/best/avenger‘, array(‘as‘=>‘ironman‘,function(){return‘Tony Stark‘;}));Route::get(‘example‘,function(){return URL::route(‘ironman‘);});
使用URL参数
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
// Route to the Stark controller.Route::get(‘tony/the/{first}/genius‘,‘Stark@tony‘);Route::get(‘example‘,function(){return URL::action(‘Stark@tony‘, array(‘narcissist‘));});
到资源的绝对URL
Route::get(‘example‘,function(){return URL::asset(‘img/logo.png‘);});
返回http://myapp.dev/img/logo.png,同样,使用HTTPS
return URL::asset(‘img/logo.png‘,true);
或是
return URL::secureAsset(‘img/logo.png‘);
在视图中生成URL
使用url()在视图中生成URL,方法跟参数跟以上的没什么区别,使用如下
<ahref="">My Route</a>
或是
<ahref="">My Route</a>
使用路由别名
<ahref="">My Route</a>
使用控制器
<ahref="">My Route</a>
使用资源
<ahref="">My Route</a><ahref="">My Route</a>
结束
关于url可以看官网的api