laravel之路由

laravel之路由设置

laravel之路由

代码如下:

laravel之路由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
上一篇:优化Python代码的4种方法


下一篇:ubuntu下图形程序自启动的几种方法