質問編集履歴
3
追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,6 +12,7 @@
|
|
12
12
|
.content
|
13
13
|
.id
|
14
14
|
|
15
|
+
#### モデル、マイグレーション
|
15
16
|
```
|
16
17
|
[Blog_php]
|
17
18
|
|
@@ -28,6 +29,7 @@
|
|
28
29
|
}
|
29
30
|
|
30
31
|
[Blogマイグレーション ]
|
32
|
+
|
31
33
|
public function up()
|
32
34
|
{
|
33
35
|
Schema::create('blogs', function(Blueprint $table)
|
@@ -42,6 +44,7 @@
|
|
42
44
|
}
|
43
45
|
|
44
46
|
[skillマイグレーション ]
|
47
|
+
|
45
48
|
public function up()
|
46
49
|
{
|
47
50
|
Schema::create('skills', function(Blueprint $table)
|
2
追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,6 +12,50 @@
|
|
12
12
|
.content
|
13
13
|
.id
|
14
14
|
|
15
|
+
```
|
16
|
+
[Blog_php]
|
17
|
+
|
18
|
+
public function blogSkills()
|
19
|
+
{
|
20
|
+
return $this->hasMany(BlogSkill::class, 'blog_id');
|
21
|
+
}
|
22
|
+
|
23
|
+
[skill.php]
|
24
|
+
|
25
|
+
public function blogSkills()
|
26
|
+
{
|
27
|
+
return $this->hasMany(BlogSkill::class, 'skill_id');
|
28
|
+
}
|
29
|
+
|
30
|
+
[Blogマイグレーション ]
|
31
|
+
public function up()
|
32
|
+
{
|
33
|
+
Schema::create('blogs', function(Blueprint $table)
|
34
|
+
{
|
35
|
+
$table->integer('id', true);
|
36
|
+
$table->string('content', 200);
|
37
|
+
$table->boolean('status');
|
38
|
+
$table->dateTime('published_at')->nullable();
|
39
|
+
$table->timestamps();
|
40
|
+
$table->softDeletes();
|
41
|
+
});
|
42
|
+
}
|
43
|
+
|
44
|
+
[skillマイグレーション ]
|
45
|
+
public function up()
|
46
|
+
{
|
47
|
+
Schema::create('skills', function(Blueprint $table)
|
48
|
+
{
|
49
|
+
$table->integer('id', true);
|
50
|
+
$table->string('skill_name', 50)->unique('skill_name');
|
51
|
+
$table->boolean('status');
|
52
|
+
$table->timestamps();
|
53
|
+
$table->softDeletes();
|
54
|
+
});
|
55
|
+
}
|
56
|
+
```
|
57
|
+
|
58
|
+
|
15
59
|
#### 内容
|
16
60
|
現在、Eloquentを利用してskillsテーブルのstatusが1のものだけを取得したいと考えています。
|
17
61
|
しかし下記のソースコードでは、対応するskills_idが複数あり、一つでもstatusが1であれば、その他のstatusが0だとしても弾かれることはなく取得してしまいます。
|
1
誤字
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
Laravel Eloquentリレーション先の結果によってデータを取得する。
|
body
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
|
27
27
|
### 該当のソースコード
|
28
28
|
|
29
|
-
```
|
29
|
+
```Laravel
|
30
30
|
Blog::whereHas('blogSkills', function($query){
|
31
31
|
$query->whereHas('skill', function($query2){
|
32
32
|
$query2->where('status', '=', 1);
|