Skip to content

Commit 8c6a56f

Browse files
author
singi.qin
committed
feat: laravel
1 parent e6d17ae commit 8c6a56f

File tree

10 files changed

+114
-165
lines changed

10 files changed

+114
-165
lines changed

blog/2019-05-28-first-blog-post.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

blog/2019-05-29-long-blog-post.md

Lines changed: 0 additions & 44 deletions
This file was deleted.

blog/2021-08-01-mdx-blog-post.mdx

Lines changed: 0 additions & 24 deletions
This file was deleted.
-93.9 KB
Binary file not shown.

blog/2021-08-26-welcome/index.md

Lines changed: 0 additions & 29 deletions
This file was deleted.

blog/2025-07-08-php8_x.md/index.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ authors: [singi]
55
tags: [php8, feature]
66
---
77

8-
# php8.x 常用新特性
9-
108
## [php8.0](https://www.php.net/releases/8.0/zh.php)
119

1210
### 命名参数
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
slug: laravel9模型关联
3+
title: laravel9模型关联
4+
authors: [singi]
5+
tags: [laravel, 模型关联]
6+
---
7+
8+
## 一对一关联
9+
10+
### 表结构
11+
12+
用户表,头像表
13+
14+
```text
15+
users
16+
id
17+
nickname
18+
19+
avatars
20+
id
21+
user_id
22+
```
23+
24+
### 定义模型
25+
26+
```php
27+
namespace App\Models;
28+
29+
use Illuminate\Database\Eloquent\Model;
30+
31+
class User extends Model
32+
{
33+
public function avatar()
34+
{
35+
return $this->hasOne(Avatar::class);
36+
}
37+
}
38+
```
39+
40+
```php
41+
namespace App\Models;
42+
43+
use Illuminate\Database\Eloquent\Model;
44+
45+
class Avatar extends Model
46+
{
47+
public function user()
48+
{
49+
return $this->belongsTo(User::class);
50+
}
51+
}
52+
```
53+
54+
## 一对多关联
55+
56+
### 表结构
57+
58+
用户表(同上), 订单表
59+
60+
```text
61+
orders
62+
id
63+
user_id
64+
no
65+
title
66+
```
67+
68+
### 定义模型
69+
70+
```php
71+
namespace App\Models;
72+
73+
use Illuminate\Database\Eloquent\Model;
74+
75+
class User extends Model
76+
{
77+
public function orders()
78+
{
79+
return $this->hasMany(Order::class);
80+
}
81+
}
82+
```
83+
84+
```php
85+
namespace App\Models;
86+
87+
use Illuminate\Database\Eloquent\Model;
88+
89+
class Order extends Model
90+
{
91+
public function user()
92+
{
93+
return $this->belongsTo(User::class);
94+
}
95+
}
96+
```

blog/authors.yml

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,7 @@
1-
yangshun:
2-
name: Yangshun Tay
3-
title: Ex-Meta Staff Engineer, Co-founder GreatFrontEnd
4-
url: https://linkedin.com/in/yangshun
5-
image_url: https://github.com/yangshun.png
6-
page: true
7-
socials:
8-
x: yangshunz
9-
linkedin: yangshun
10-
github: yangshun
11-
newsletter: https://www.greatfrontend.com
12-
13-
slorber:
14-
name: Sébastien Lorber
15-
title: Docusaurus maintainer
16-
url: https://sebastienlorber.com
17-
image_url: https://github.com/slorber.png
18-
page:
19-
# customize the url of the author page at /blog/authors/<permalink>
20-
permalink: '/all-sebastien-lorber-articles'
21-
socials:
22-
x: sebastienlorber
23-
linkedin: sebastienlorber
24-
github: slorber
25-
newsletter: https://thisweekinreact.com
26-
271
singi:
282
name: Singi Qin
293
title: maintainer
30-
url: https://sebastienlorber.com
31-
image_url: https://github.com/singi2016cn.png
4+
url: https://singi2016cn.github.io
325
page:
336
permalink: '/php8_x'
347
socials:

blog/tags.yml

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,3 @@
1-
facebook:
2-
label: Facebook
3-
permalink: /facebook
4-
description: Facebook tag description
5-
6-
hello:
7-
label: Hello
8-
permalink: /hello
9-
description: Hello tag description
10-
11-
docusaurus:
12-
label: Docusaurus
13-
permalink: /docusaurus
14-
description: Docusaurus tag description
15-
16-
hola:
17-
label: Hola
18-
permalink: /hola
19-
description: Hola tag description
20-
211
php8:
222
label: php8
233
permalink: /php8
@@ -27,3 +7,13 @@ feature:
277
label: feature
288
permalink: /feature
299
description: feature
10+
11+
laravel:
12+
label: laravel
13+
permalink: /laravel
14+
description: laravel
15+
16+
模型关联:
17+
label: 模型关联
18+
permalink: /模型关联
19+
description: 模型关联

docusaurus.config.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ const config: Config = {
7979
src: 'img/logo.svg',
8080
},
8181
items: [
82-
{
83-
type: 'docSidebar',
84-
sidebarId: 'tutorialSidebar',
85-
position: 'left',
86-
label: 'Tutorial',
87-
},
82+
// {
83+
// type: 'docSidebar',
84+
// sidebarId: 'tutorialSidebar',
85+
// position: 'left',
86+
// label: 'Tutorial',
87+
// },
8888
{to: '/blog', label: 'Blog', position: 'left'},
8989
{
9090
href: 'https://github.com/facebook/docusaurus',
@@ -143,6 +143,7 @@ const config: Config = {
143143
darkTheme: prismThemes.dracula,
144144
},
145145
} satisfies Preset.ThemeConfig,
146+
146147
themes: [
147148
// ... Your other themes.
148149
[

0 commit comments

Comments
 (0)