質問編集履歴

2

Messageモデル、Roomモデルの記載

2021/12/14 22:56

投稿

Yoshiaki_Miyata
test CHANGED
File without changes
test CHANGED
@@ -111,3 +111,57 @@
111
111
  }
112
112
 
113
113
  ```
114
+
115
+
116
+
117
+ ```
118
+
119
+ Messageモデル
120
+
121
+ <?php
122
+
123
+
124
+
125
+ namespace App\Models;
126
+
127
+
128
+
129
+ use Illuminate\Database\Eloquent\Factories\HasFactory;
130
+
131
+ use Illuminate\Database\Eloquent\Model;
132
+
133
+
134
+
135
+ class Message extends Model
136
+
137
+ {
138
+
139
+ use HasFactory;
140
+
141
+ public function room()
142
+
143
+ {
144
+
145
+ return $this->belongsTo('App\Models\Room');
146
+
147
+ }
148
+
149
+ }
150
+
151
+
152
+
153
+ ```
154
+
155
+ Roomモデル
156
+
157
+ ```
158
+
159
+ public function messages()
160
+
161
+ {
162
+
163
+ return $this->hasMany('App\Models\Message');
164
+
165
+ }
166
+
167
+ ```

1

Messageコントローラーの記載

2021/12/14 22:56

投稿

Yoshiaki_Miyata
test CHANGED
File without changes
test CHANGED
@@ -75,3 +75,39 @@
75
75
 
76
76
 
77
77
  ![イメージ説明](9836875bd5381325a1a0150c63a00e3c.png)
78
+
79
+
80
+
81
+ Messageコントローラー
82
+
83
+ ```
84
+
85
+ class MessageController extends Controller
86
+
87
+ {
88
+
89
+ public function CompanyMessageStore(Request $request)
90
+
91
+ {
92
+
93
+ $user = Auth::user();
94
+
95
+
96
+
97
+ $message = new Message();
98
+
99
+
100
+
101
+ $message->text = $request->text();
102
+
103
+ $message->save();
104
+
105
+
106
+
107
+ return back();
108
+
109
+ }
110
+
111
+ }
112
+
113
+ ```