質問編集履歴
7
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,18 +24,6 @@
|
|
24
24
|
|
25
25
|
|
26
26
|
|
27
|
-
再修正
|
28
|
-
|
29
|
-
-----------------------
|
30
|
-
|
31
|
-
$post = new Post;//追加
|
32
|
-
|
33
|
-
//エラー
|
34
|
-
|
35
|
-
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'post_id' cannot be null (SQL: insert into `post_tag` (`created_at`, `post_id`, `tag_id`, `updated_at`) values (2020-04-29 21:59:21, ?, 1, 2020-04-29 21:59:21)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
27
|
TOXI法によるタグ付け機能を考えています
|
40
28
|
|
41
29
|
テーブルはこのような感じです
|
6
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,6 +16,24 @@
|
|
16
16
|
|
17
17
|
[https://qiita.com/AkiYanagimoto/items/b363d673d9f2bf63fc0f](https://qiita.com/AkiYanagimoto/items/b363d673d9f2bf63fc0f)
|
18
18
|
|
19
|
+
修正後------------------------------------
|
20
|
+
|
21
|
+
$post->tags()->attach($tags_id);
|
22
|
+
|
23
|
+
「Call to a member function tags() on array」
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
再修正
|
28
|
+
|
29
|
+
-----------------------
|
30
|
+
|
31
|
+
$post = new Post;//追加
|
32
|
+
|
33
|
+
//エラー
|
34
|
+
|
35
|
+
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'post_id' cannot be null (SQL: insert into `post_tag` (`created_at`, `post_id`, `tag_id`, `updated_at`) values (2020-04-29 21:59:21, ?, 1, 2020-04-29 21:59:21)
|
36
|
+
|
19
37
|
|
20
38
|
|
21
39
|
TOXI法によるタグ付け機能を考えています
|
@@ -52,16 +70,6 @@
|
|
52
70
|
|
53
71
|
|
54
72
|
|
55
|
-
修正後------------------------------------
|
56
|
-
|
57
|
-
$post->tags()->attach($tags_id);
|
58
|
-
|
59
|
-
「Call to a member function tags() on array」
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
73
|
|
66
74
|
|
67
75
|
```ここに言語を入力
|
@@ -92,7 +100,9 @@
|
|
92
100
|
|
93
101
|
{
|
94
102
|
|
103
|
+
$post = new Post;//追加
|
104
|
+
|
95
|
-
$post = $request->validate([
|
105
|
+
$post = $request->validate([
|
96
106
|
|
97
107
|
'title' => 'required|max:50',
|
98
108
|
|
5
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,6 +12,10 @@
|
|
12
12
|
|
13
13
|
解決方法をご教示くださいよろしくお願いします。
|
14
14
|
|
15
|
+
【参考サイト】
|
16
|
+
|
17
|
+
[https://qiita.com/AkiYanagimoto/items/b363d673d9f2bf63fc0f](https://qiita.com/AkiYanagimoto/items/b363d673d9f2bf63fc0f)
|
18
|
+
|
15
19
|
|
16
20
|
|
17
21
|
TOXI法によるタグ付け機能を考えています
|
4
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -54,7 +54,7 @@
|
|
54
54
|
|
55
55
|
「Call to a member function tags() on array」
|
56
56
|
|
57
|
-
|
57
|
+
|
58
58
|
|
59
59
|
|
60
60
|
|
3
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,14 +8,46 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
|
12
|
-
|
13
11
|
このエラーが起こる原因が掴めません
|
14
12
|
|
15
13
|
解決方法をご教示くださいよろしくお願いします。
|
16
14
|
|
17
15
|
|
18
16
|
|
17
|
+
TOXI法によるタグ付け機能を考えています
|
18
|
+
|
19
|
+
テーブルはこのような感じです
|
20
|
+
|
21
|
+
**posts**
|
22
|
+
|
23
|
+
|id|title|body|
|
24
|
+
|
25
|
+
|:--|:--:|--:|
|
26
|
+
|
27
|
+
||||
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
**post_tag**
|
32
|
+
|
33
|
+
|id|post_id|tag_id|
|
34
|
+
|
35
|
+
|:--|:--:|--:|
|
36
|
+
|
37
|
+
||||
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
**tags**
|
42
|
+
|
43
|
+
|id|tag_name|
|
44
|
+
|
45
|
+
|:--|:--:|
|
46
|
+
|
47
|
+
||||
|
48
|
+
|
49
|
+
|
50
|
+
|
19
51
|
修正後------------------------------------
|
20
52
|
|
21
53
|
$post->tags()->attach($tags_id);
|
2
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,7 +16,19 @@
|
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
+
修正後------------------------------------
|
20
|
+
|
21
|
+
$post->tags()->attach($tags_id);
|
22
|
+
|
23
|
+
「Call to a member function tags() on array」
|
24
|
+
|
25
|
+
-------------------------------------------
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
19
|
-
```
|
31
|
+
```ここに言語を入力
|
20
32
|
|
21
33
|
#PostsController.php
|
22
34
|
|
@@ -44,6 +56,16 @@
|
|
44
56
|
|
45
57
|
{
|
46
58
|
|
59
|
+
$post = $request->validate([ //修正
|
60
|
+
|
61
|
+
'title' => 'required|max:50',
|
62
|
+
|
63
|
+
'body' => 'required|max:2000',
|
64
|
+
|
65
|
+
]);
|
66
|
+
|
67
|
+
|
68
|
+
|
47
69
|
preg_match_all('/#([a-zA-z0-90-9ぁ-んァ-ヶ亜-熙]+)/u', $request->tags, $match);
|
48
70
|
|
49
71
|
|
@@ -68,7 +90,7 @@
|
|
68
90
|
|
69
91
|
|
70
92
|
|
71
|
-
|
93
|
+
|
72
94
|
|
73
95
|
$post->tags()->attach($tags_id);//エラー箇所
|
74
96
|
|
@@ -80,31 +102,75 @@
|
|
80
102
|
|
81
103
|
}
|
82
104
|
|
105
|
+
|
106
|
+
|
83
107
|
```
|
84
108
|
|
85
|
-
```ここに言語を入力
|
86
109
|
|
87
|
-
# Post.php
|
88
110
|
|
111
|
+
```
|
112
|
+
|
113
|
+
#Post.php
|
114
|
+
|
115
|
+
<?php
|
116
|
+
|
117
|
+
namespace App;
|
118
|
+
|
119
|
+
use Illuminate\Database\Eloquent\Model;
|
120
|
+
|
121
|
+
class Post extends Model
|
122
|
+
|
123
|
+
{
|
124
|
+
|
125
|
+
protected $fillable = [
|
126
|
+
|
127
|
+
'title',
|
128
|
+
|
129
|
+
'body',
|
130
|
+
|
131
|
+
];
|
132
|
+
|
89
|
-
public function tags()
|
133
|
+
public function tags()
|
90
134
|
|
91
135
|
{
|
92
136
|
|
93
|
-
return $this->belongsToMany('App\Tag');
|
137
|
+
return $this->belongsToMany('App\Tag','post_tag');//修正
|
94
138
|
|
95
139
|
}
|
96
140
|
|
97
141
|
|
98
142
|
|
143
|
+
{
|
144
|
+
|
145
|
+
|
146
|
+
|
99
147
|
# Tag.php
|
100
148
|
|
101
|
-
p
|
149
|
+
<?php
|
102
150
|
|
103
|
-
|
151
|
+
namespace App;
|
104
152
|
|
105
|
-
|
153
|
+
use Illuminate\Database\Eloquent\Model;
|
106
154
|
|
155
|
+
class Tag extends Model
|
156
|
+
|
157
|
+
{
|
158
|
+
|
159
|
+
protected $fillable = [
|
160
|
+
|
161
|
+
'tag_name',
|
162
|
+
|
163
|
+
];
|
164
|
+
|
165
|
+
public function posts()
|
166
|
+
|
167
|
+
{
|
168
|
+
|
169
|
+
return $this->belongsToMany('App\Post','post_tag');//修正
|
170
|
+
|
107
|
-
}
|
171
|
+
}
|
172
|
+
|
173
|
+
}
|
108
174
|
|
109
175
|
```
|
110
176
|
|
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -68,7 +68,7 @@
|
|
68
68
|
|
69
69
|
|
70
70
|
|
71
|
-
$post = $request
|
71
|
+
$post = $request;
|
72
72
|
|
73
73
|
$post->tags()->attach($tags_id);//エラー箇所
|
74
74
|
|