質問編集履歴
1
モデル情報の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -41,4 +41,117 @@
|
|
41
41
|
期待値はhogeraのレコード1件のみ取得。
|
42
42
|
|
43
43
|
もろもろすっとばしていますが・・・(;´∀`)
|
44
|
-
よろしくお願いします。
|
44
|
+
よろしくお願いします。
|
45
|
+
|
46
|
+
下記、モデル情報です。
|
47
|
+
|
48
|
+
#### stores
|
49
|
+
|
50
|
+
```
|
51
|
+
<?php
|
52
|
+
|
53
|
+
namespace App\Models;
|
54
|
+
|
55
|
+
use Illuminate\Database\Eloquent\Model;
|
56
|
+
use Illuminate\Database\Eloquent\SoftDeletes;
|
57
|
+
|
58
|
+
class Stores extends Model
|
59
|
+
{
|
60
|
+
use SoftDeletes;
|
61
|
+
|
62
|
+
/**
|
63
|
+
* モデルと関連しているテーブル
|
64
|
+
*
|
65
|
+
* @var string
|
66
|
+
*/
|
67
|
+
protected $table = 'stores';
|
68
|
+
|
69
|
+
/**
|
70
|
+
* 日付のデータ型でFormatを利用するカラムを指定
|
71
|
+
*/
|
72
|
+
protected $dates = [
|
73
|
+
'created_at',
|
74
|
+
'updated_at',
|
75
|
+
'deleted_at'
|
76
|
+
];
|
77
|
+
|
78
|
+
/**
|
79
|
+
* コース情報とのリレーション
|
80
|
+
* @return type
|
81
|
+
*/
|
82
|
+
public function storeCourses()
|
83
|
+
{
|
84
|
+
return $this->belongsToMany(StoreCourses::class, 'courses_stores', 'store_id', 'course_id');
|
85
|
+
}
|
86
|
+
}
|
87
|
+
```
|
88
|
+
|
89
|
+
#### courses_stores
|
90
|
+
|
91
|
+
```
|
92
|
+
<?php
|
93
|
+
namespace App\Models;
|
94
|
+
|
95
|
+
use Illuminate\Database\Eloquent\Model;
|
96
|
+
use Illuminate\Database\Eloquent\SoftDeletes;
|
97
|
+
|
98
|
+
class CoursesStores extends Model
|
99
|
+
{
|
100
|
+
use SoftDeletes;
|
101
|
+
|
102
|
+
/**
|
103
|
+
* モデルと関連しているテーブル
|
104
|
+
*
|
105
|
+
* @var string
|
106
|
+
*/
|
107
|
+
protected $table = 'courses_stores';
|
108
|
+
|
109
|
+
/**
|
110
|
+
* 日付のデータ型でFormatを利用するカラムを指定
|
111
|
+
*/
|
112
|
+
protected $dates = [
|
113
|
+
'created_at',
|
114
|
+
'updated_at',
|
115
|
+
'deleted_at'
|
116
|
+
];
|
117
|
+
}
|
118
|
+
```
|
119
|
+
|
120
|
+
#### courses
|
121
|
+
|
122
|
+
```
|
123
|
+
<?php
|
124
|
+
namespace App\Models;
|
125
|
+
|
126
|
+
use Illuminate\Database\Eloquent\Model;
|
127
|
+
use Illuminate\Database\Eloquent\SoftDeletes;
|
128
|
+
|
129
|
+
class Courses extends Model
|
130
|
+
{
|
131
|
+
use SoftDeletes;
|
132
|
+
/**
|
133
|
+
* モデルと関連しているテーブル
|
134
|
+
*
|
135
|
+
* @var string
|
136
|
+
*/
|
137
|
+
protected $table = 'courses';
|
138
|
+
|
139
|
+
/**
|
140
|
+
* 日付のデータ型でFormatを利用するカラムを指定
|
141
|
+
*/
|
142
|
+
protected $dates = [
|
143
|
+
'created_at',
|
144
|
+
'updated_at',
|
145
|
+
'deleted_at'
|
146
|
+
];
|
147
|
+
|
148
|
+
/**
|
149
|
+
* 店舗情報とのリレーション
|
150
|
+
* @return type
|
151
|
+
*/
|
152
|
+
public function stores()
|
153
|
+
{
|
154
|
+
return $this->belongsToMany(Stores::class, 'courses_stores', 'course_id', 'store_id');
|
155
|
+
}
|
156
|
+
}
|
157
|
+
```
|