Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
檀越@新空间
Coding Tree
提交
edbb60ef
C
Coding Tree
项目概览
檀越@新空间
/
Coding Tree
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Coding Tree
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
“66054984cd6638726497404aba613cc52fdbe339”上不存在“...advbox/git@gitcode.net:s920243400/PaddleDetection.git”
提交
edbb60ef
编写于
6月 28, 2022
作者:
彭世瑜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix
上级
f10f9e6a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
202 addition
and
2 deletion
+202
-2
.nvmrc
.nvmrc
+1
-1
blog/laravel/route.md
blog/laravel/route.md
+201
-1
未找到文件。
.nvmrc
浏览文件 @
edbb60ef
v1
2.22.6
v1
6.14.0
\ No newline at end of file
blog/laravel/route.md
浏览文件 @
edbb60ef
...
@@ -212,4 +212,204 @@ class TaskController extends Controller
...
@@ -212,4 +212,204 @@ class TaskController extends Controller
}
}
```
```
https://www.bilibili.com/video/BV1gE411j78F?p=4&spm_id_from=pageDriver&vd_source=efbb4dc944fa761b6e016ce2ca5933da
\ No newline at end of file
## 路由命名
```
php
// 指定路由的名称
Route
::
get
(
'/task'
,
function
(){
return
'task'
;
})
->
name
(
'index.task'
);
// 使用助手函数生成URL(URL是URI的子集)
Route
::
get
(
'/url'
,
function
(){
return
route
(
'index.task'
);
// http://127.0.0.1:8000/task
});
// 传参
Route
::
get
(
'/url'
,
function
(){
return
route
(
'index.task'
,
[
'name'
=>
'Tom'
]);
// http://127.0.0.1:8000/task?name=Tom
});
// 路由跳转
Route
::
get
(
'/url'
,
function
(){
return
redirect
()
->
route
(
'index.task'
,
[
'name'
=>
'Tom'
]);
// 跳转地址:http://127.0.0.1:8000/task?name=Tom
});
// 生成相对地址
Route
::
get
(
'/url'
,
function
(){
return
route
(
'index.task'
,
[
'name'
=>
'Tom'
],
false
);
// /task?name=Tom
});
```
## 路由分组
```
php
// 添加路由前缀
Route
::
group
([
'prefix'
=>
'api'
],
function
()
{
// http://127.0.0.1:8000/api/index
Route
::
get
(
'/index'
,
function
()
{
return
'index'
;
});
// http://127.0.0.1:8000/api/task
Route
::
get
(
'/task'
,
function
()
{
return
'task'
;
});
});
// 等价于(推荐)
Route
::
prefix
(
'api'
)
->
group
(
function
()
{
// http://127.0.0.1:8000/api/index
Route
::
get
(
'/index'
,
function
()
{
return
'index'
;
});
// http://127.0.0.1:8000/api/task
Route
::
get
(
'/task'
,
function
()
{
return
'task'
;
});
});
// 路由中间件
Route
::
middleware
(
'middleware'
)
->
group
(
function
()
{});
// 子域路由
Route
::
domain
(
'127.0.0.1'
)
->
group
(
function
()
{});
// 命名空间
Route
::
namespace
(
'Admin'
)
->
group
(
function
()
{});
// 路由名称前缀
Route
::
name
(
'admin.'
)
->
group
(
function
()
{
Route
::
get
(
'/task'
,
function
()
{
return
'task'
;
})
->
name
(
'task'
);
// admin.task
});
```
## 单动作控制器
```
bash
php artisan make:controller OneController
--invokable
```
```
php
<?php
namespace
App\Http\Controllers
;
class
OneController
extends
Controller
{
public
function
__invoke
()
{
return
'one'
;
}
}
```
路由
```
php
// http://127.0.0.1:8000/one
Route
::
get
(
'/one'
,
OneController
::
class
);
```
## 回退路由
```
php
// 错误处理,注意:必须放在所有路由最底部
Route
::
fallback
(
function
()
{
return
'error'
;
// 返回404页面
// return view('404');
});
```
## 当前路由
### 当前路由信息
```
php
Route
::
get
(
'/task'
,
function
(){
return
json_encode
(
Route
::
current
());
});
```
输出
```
json
{
"uri"
:
"task"
,
"methods"
:
[
"GET"
,
"HEAD"
],
"action"
:
{
"middleware"
:
[
"web"
],
"uses"
:
{},
"namespace"
:
null
,
"prefix"
:
""
,
"where"
:
[]
},
"isFallback"
:
false
,
"controller"
:
null
,
"defaults"
:
[],
"wheres"
:
{
"id"
:
"[0-9]+"
},
"parameters"
:
[],
"parameterNames"
:
[],
"computedMiddleware"
:
[
"web"
],
"compiled"
:
{}
}
```
### 当前路由名称
```
php
Route
::
get
(
'/task'
,
function
(){
return
Route
::
currentRouteName
();
// index.task
})
->
name
(
'index.task'
);
```
### 当前路由指向的方法
```
php
<?php
namespace
App\Http\Controllers
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\Route
;
class
TaskController
extends
Controller
{
public
function
index
()
{
return
Route
::
currentRouteAction
();
// App\Http\Controllers\TaskController@index
}
}
```
```
php
Route
::
get
(
'/task'
,[
TaskController
::
class
,
'index'
]);
```
https://www.bilibili.com/video/BV1gE411j78F?p=6&spm_id_from=pageDriver
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录