laravel框架——路由

62 篇文章 0 订阅
33 篇文章 0 订阅
//用例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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值