Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
檀越@新空间
Coding Tree
提交
9c055007
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看板
You need to sign in or sign up before continuing.
提交
9c055007
编写于
7月 19, 2022
作者:
彭世瑜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix
上级
436c1bdc
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
152 addition
and
3 deletion
+152
-3
blog/laravel/cookie.md
blog/laravel/cookie.md
+42
-0
blog/laravel/index.md
blog/laravel/index.md
+4
-1
blog/laravel/request-method.md
blog/laravel/request-method.md
+5
-2
blog/laravel/session.md
blog/laravel/session.md
+101
-0
未找到文件。
blog/laravel/cookie.md
0 → 100644
浏览文件 @
9c055007
# Cookie
获取Cookie
```
php
// 注意 Laravel 中 cookie 都是加密的,原生 cookie 只能获取加密信息
return
$_COOKIE
[
'laravel_session'
];
// eyJpdiI6IjBINjVlYW8vSkM5NnVVZW1hUm81T1E9PSIsInZhbHVlIjoiUm16YmdTelZiMUpJZXQ2elpYcDc1dVB0UXFhSWpxaWsyOFNNTzZBZWhVUTZyRjRzWWoycmdTQzI3ZnM4eklpWUZNd21SSlNIK3d4UjdWZmpKSm9JWWx4M0RDTktDOGh2L3B0RlAvMFozYlBVL0hvOEhKYXBsLzQwVmlqMEh5blkiLCJtYWMiOiI2ZTNkZjQxN2Y1ZjAxYmYwZDQxYjg3MTAxNGZmMzVkZjFhZDE2MzhjZjdlYWFjMzc5YTlmYWQ2OGU3ZDJjMjE4IiwidGFnIjoiIn0=
//使用 request()->cookie 获取解密后的 cookie 信息
return
request
()
->
cookie
(
'laravel_session'
);
// sh6TujUjSKMI6ENbXbBwy2eeuTXsuNSkCDUsQGHf
//使用Cookie获取,
// Illuminate\Support\Facades\Cookie;
return
Cookie
::
get
(
'laravel_session'
);
// sh6TujUjSKMI6ENbXbBwy2eeuTXsuNSkCDUsQGHf
```
创建cookie
```
php
return
response
(
'Hello Cookie'
)
->
cookie
(
'name'
,
'Mr.Lee'
,
10
);
//推荐这个,清爽很多
Cookie
::
queue
(
'age'
,
100
,
10
);
//助手函数,创建一个实例,让写入可以更加灵活
$cookie
=
cookie
(
'gender'
,
'男'
,
10
);
Cookie
::
queue
(
$cookie
);
// 完整版 过期时间(分钟),路径,域名,https,仅 http
cookie
(
$name
,
$value
,
$minutes
,
$path
,
$domain
,
$secure
,
$httpOnly
)
```
默认cookie是加密存放的,如果想某个cookie不加密,在中间件文件夹设置
```
php
// Http/Middleware/milldelEncryptCookies.php
protected
$except
=
[
'name'
];
```
\ No newline at end of file
blog/laravel/index.md
浏览文件 @
9c055007
...
...
@@ -56,6 +56,9 @@ dev:
[
生成 URL
](
/blog/laravel/url.md
)
[
Cookie
](
/blog/laravel/cookie.md
)
[
Session
](
/blog/laravel/session.md
)
https://www.bilibili.com/video/BV1gE411j78F?p=34&spm_id_from=pageDriver&vd_source=efbb4dc944fa761b6e016ce2ca5933da
\ No newline at end of file
https://www.bilibili.com/video/BV1gE411j78F?p=38&spm_id_from=pageDriver&vd_source=efbb4dc944fa761b6e016ce2ca5933da
\ No newline at end of file
blog/laravel/request-method.md
浏览文件 @
9c055007
...
...
@@ -13,11 +13,14 @@ $request->input();
$request
->
name
;
```
接受数组
接受
二维
数组
```
html
<form
action=
"/post"
method=
"get"
>
<input
type=
"checkbox"
name=
"select[][a]"
value=
"1"
>
<input
type=
"checkbox"
name=
"select[][b]"
value=
"2"
>
<input
type=
"checkbox"
name=
"select[][c]"
value=
"3"
>
<button
type=
"submit"
>
发送
</button>
<input
type=
"checkbox"
name=
"select[][a]"
value=
"1"
>
<input
type=
"checkbox"
name=
"select[][b]"
value=
"2"
>
<input
type=
"checkbox"
name=
"select[][c]"
value=
"3"
>
<button
type=
"submit"
>
发送
</button>
</form>
```
...
...
blog/laravel/session.md
0 → 100644
浏览文件 @
9c055007
# Session
启动Web后,默认会有session
获取所有session
```
php
return
request
()
->
session
()
->
all
()
```
获取某一个session
```
php
// 获取其中一个 session
return
request
()
->
session
()
->
get
(
'_token'
);
// 参数 2,闭包设置默认值
return
request
()
->
session
()
->
get
(
'name'
,
function
()
{
return
'no session name'
;
});
return
Session
::
get
(
'_token'
);
```
助手函数session()
```
php
// 获取 session 值
return
session
(
'_token'
);
// 获取 session 值并设置默认值
return
session
(
'name'
,
'no session name'
);
```
判断是否存在session有两种方案
```
php
// 判断是否存在且不为null
return
Session
::
has
(
'name'
);
// 判断是否存在,即使是null
return
Session
::
exists
(
'name'
);
```
存储session值
```
php
//设置 session 值
session
([
'name'
=>
'Mr.Lee'
]);
// 也支持 request()存储
Session
::
put
(
'name'
,
'MrWang'
);
```
存储数组
```
php
//session 数组方式
Session
::
push
(
'info.name'
,
'Mr.Lee'
);
Session
::
push
(
'info.name'
,
'Mr.Wang'
);
Session
::
push
(
'info.name'
,
'Mr.Zhang'
);
return
Session
::
get
(
'info'
);
```
闪存数据
```
php
// 存储的 session 只能被获取一次,然后自动删除,flash 也称为闪存数据
Session
::
flash
(
'name'
,
'Mr.Lee'
);
// 本次请求获取,不要删除数据,给下一次请求时再自行删除,这是保存所有闪存数据
Session
::
reflash
();
// 保存单独的删除数据
Session
::
keep
([
'name'
]);
return
Session
::
get
(
'name'
);
```
删除一条或多条 session 数据
```
php
// 删除一条数据
Session
::
forget
(
'name'
);
Session
::
forget
([
'name'
])
return
Session
::
get
(
'name'
);
// 删除一条数据,并返回
Session
::
pull
(
'info'
);
// 删除所有数据
Session
::
flush
();
```
重新生成 SessionID
```
php
//重新生成 SessionID
Session
::
regenerate
();
// 获取 SessionID
return
Cookie
::
get
(
'laravel_session'
);
```
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录