标签:request info 默认值 .com reg 代码 uri match 访问
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‘);
});
标签:request info 默认值 .com reg 代码 uri match 访问
原文地址:https://www.cnblogs.com/nzc520/p/10549862.html