Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
檀越@新空间
Coding Tree
提交
c7f5f45a
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看板
“34491d6a8ff2e5e38bfd466450374cab06ace8c7”上不存在“paddle/git@gitcode.net:Crayonxin2000/Paddle.git”
提交
c7f5f45a
编写于
7月 01, 2022
作者:
彭世瑜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix
上级
efcb9af9
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
142 addition
and
1 deletion
+142
-1
blog/laravel/csrf.md
blog/laravel/csrf.md
+46
-0
blog/laravel/database.md
blog/laravel/database.md
+87
-0
blog/laravel/index.md
blog/laravel/index.md
+4
-0
blog/laravel/route.md
blog/laravel/route.md
+5
-1
未找到文件。
blog/laravel/csrf.md
0 → 100644
浏览文件 @
c7f5f45a
# 表单伪造和 CSRF 保护
表单提交会出现419错误
```
html
<form
action=
"/task/getform"
method=
"post"
>
用户名:
<input
type=
"text"
name=
"user"
>
<button
type=
"submit"
>
提交
</button>
</form>
```
csrf_token
```
html
<!-- CSRF令牌保护 -->
<input
type=
"hidden"
name=
"_token"
value=
"{{csrf_token()}}"
>
<!-- 修改提交方式 -->
<input
type=
"hidden"
name=
"_method"
value=
"PUT"
>
<!-- 快捷方式 -->
@csrf
@method('PUT')
```
配置白名单
```
php
<?php
namespace
App\Http\Middleware
;
use
Illuminate\Foundation\Http\Middleware\VerifyCsrfToken
as
Middleware
;
class
VerifyCsrfToken
extends
Middleware
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array<int, string>
*/
protected
$except
=
[
'api/*'
];
}
```
blog/laravel/database.md
0 → 100644
浏览文件 @
c7f5f45a
# 数据库
操作数据库的方式:
1.
原生
2.
查询构造器
3.
EloquentORM(关系型对象映射器)
## 数据库配置
config/database.php
```
php
<?php
return
[
'default'
=>
env
(
'DB_CONNECTION'
,
'mysql'
),
'connections'
=>
[
'mysql'
=>
[
'driver'
=>
'mysql'
,
'url'
=>
env
(
'DATABASE_URL'
),
'host'
=>
env
(
'DB_HOST'
,
'127.0.0.1'
),
'port'
=>
env
(
'DB_PORT'
,
'3306'
),
'database'
=>
env
(
'DB_DATABASE'
,
'forge'
),
'username'
=>
env
(
'DB_USERNAME'
,
'forge'
),
'password'
=>
env
(
'DB_PASSWORD'
,
''
),
'unix_socket'
=>
env
(
'DB_SOCKET'
,
''
),
'charset'
=>
'utf8mb4'
,
'collation'
=>
'utf8mb4_unicode_ci'
,
'prefix'
=>
''
,
'prefix_indexes'
=>
true
,
'strict'
=>
true
,
'engine'
=>
null
,
'options'
=>
extension_loaded
(
'pdo_mysql'
)
?
array_filter
([
PDO
::
MYSQL_ATTR_SSL_CA
=>
env
(
'MYSQL_ATTR_SSL_CA'
),
])
:
[],
],
],
];
```
.env 配置数据库
```
bash
DB_CONNECTION
=
mysql
DB_HOST
=
127.0.0.1
DB_PORT
=
3306
DB_DATABASE
=
laravel
DB_USERNAME
=
root
DB_PASSWORD
=
```
## 查询
### 原生查询
```
php
DB
::
select
(
'select * from laravel_user'
);
```
### 查询构造器
```
php
DB
::
table
(
'user'
)
->
find
(
19
);
```
### EloquentORM模型
创建模型
```
bash
php artisan make:model Http/Models/User
```
查询
```
php
User
::
all
();
```
模型编码规范要求数据表是复数
强制使用现有的数据表名
```
php
protected
$table
=
'user'
;
```
https://www.bilibili.com/video/BV1gE411j78F?p=11&spm_id_from=pageDriver&vd_source=efbb4dc944fa761b6e016ce2ca5933da
\ No newline at end of file
blog/laravel/index.md
浏览文件 @
c7f5f45a
...
@@ -21,3 +21,7 @@ dev:
...
@@ -21,3 +21,7 @@ dev:
[
安装Laravel编程环境
](
blog/laravel/install-php.md
)
[
安装Laravel编程环境
](
blog/laravel/install-php.md
)
[
Route路由
](
/blog/laravel/route.md
)
[
Route路由
](
/blog/laravel/route.md
)
[
表单伪造和 CSRF 保护
](
blog/laravel/csrf.md
)
[
数据库
](
blog/laravel/database.md
)
\ No newline at end of file
blog/laravel/route.md
浏览文件 @
c7f5f45a
...
@@ -622,4 +622,8 @@ Route::ApiResource('blogs', BlogController::class);
...
@@ -622,4 +622,8 @@ Route::ApiResource('blogs', BlogController::class);
php artisan make:controller CommentController
--api
php artisan make:controller CommentController
--api
```
```
https://www.bilibili.com/video/BV1gE411j78F?p=8&spm_id_from=pageDriver&vd_source=efbb4dc944fa761b6e016ce2ca5933da
```
php
\ No newline at end of file
// 浅层嵌套
Route
::
resource
(
'blogs.comments'
,
'CommentController'
)
->
shallow
();
```
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录