laravel之路由
Posted 大黄蜂额额
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了laravel之路由相关的知识,希望对你有一定的参考价值。
laravel之路由设置
代码如下:
访问就是:
代码附上:
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It\'s a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get(\'/\', function () {
return view(\'welcome\');
});
//基本路由
Route::get(\'basic\',function(){
return \'basic\';
});
Route::post(\'basic1\',function(){
return \'basic1\';
});
//多请求路由,响应指定的路由
Route::match([\'get\',\'post\'],\'multy\',function(){
return \'multy\';
});
//响应所有的路由
Route::any(\'multy1\',function(){
return \'multy1\';
});
//响应参数
Route::get(\'user/{id}\',function($id){
return $id;
});
//路由参数使用默认值
Route::get(\'user1/{name?}\',function($name=null)
{
return $name;
});
//把name使用正则进行匹配
Route::get(\'user2/{name?}\',function($name=null)
{
return $name;
})->where(\'name\',\'[A-Za-z]+\');
//路由使用多个参数
Route::get(\'user3/{id}/{name?}\',function($id,$name)
{
return $id.\'=>\'.$name;
})->where([\'id\'=>\'[0-9]+\',\'name\'=>\'[A-Za-z]+\']);
//路由别名
Route::get(\'user/center\',[\'as\'=>\'center\',function(){
return Route(\'center\');
}]);
//在路由中输出视图
Route::get(\'shitu\',function(){
return view(\'welcome\');
});
如有疑问:https://learnku.com/docs/laravel/5.1/routing/1041#required-parameters
以上是关于laravel之路由的主要内容,如果未能解决你的问题,请参考以下文章