//用例1 get请求
Route::get('/hello',function (){
return 'Hello word';
});
Route::get('/', function () {
return view('welcome');
});
//用例2 post
Route::get('/testPost',function(){
$csrf_token = csrf_token();
$form = <<<FORM
<form action="/testPost" method="post">
<input type="hidden" name="_token" value="{$csrf_token}">
<input type="submit" value="Test">
</form>
FORM;
return $form;
});
Route::post('/testPost',function(){
return "Hello Laravel[POST]!";
});
//用例3
Route::match(['get','post'],'/match',function (){
return 'match';
});
//用例4
Route::any('/any',function (){
return 'any';
});
//用例5 单个参数
Route::get('/hello/{name}',function ($name){
return "这是接收参数 name: {$name}";
});
//用例6 多个参数
Route::get('/hello/{name}/by/{user}',function($name,$user){
return "hello {$name} by {$user}";
});
//用例7 as别名
Route::get('/hello/as',['as'=>'academy',function(){
return 'laravel as';
}]);
//用例8 as关键字
Route::get('/hello/laravelacademy',['as'=>'academy',function(){
return "hello laravel academy";
}]);
Route::get('/testNameRoute',function(){
//return route('academy'); //显示该路径
return redirect()->route('academy'); //显示该输出内容
});
Route::get('/hello/laravelacademy/{id}',['as'=>'academy',function($id){
return 'academy '.$id;
}]);
Route::get('/testNameRoute',function (){
return redirect()->route('academy',['id'=>1]);
});
//例9 分组
Route::group(['as' => 'admin::'], function () {
Route::get('dashboard', ['as' => 'dashboard', function () {
//
}]);
});
Route::get('/testNameRoute',function (){
return route('admin::dashboard');
});
原文参考:http://laravelacademy.org/laravel-tutorial-5_1;该文章为个人学习整理,需要转载请填写链接:http://blog.csdn.net/kangsf1989