首页 > 其他 > 详细

laravel之路由

时间:2019-03-18 00:47:56      阅读:192      评论:0      收藏:0      [点我收藏+]

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‘);
});

laravel之路由

原文:https://www.cnblogs.com/nzc520/p/10549862.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!