teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

解決内容の追記

2021/02/12 06:40

投稿

Sento__aa
Sento__aa

スコア21

title CHANGED
File without changes
body CHANGED
@@ -181,4 +181,35 @@
181
181
  }
182
182
  }
183
183
 
184
+ ```
185
+ ## 解決した詳細
186
+ ## EmployeesController.php
187
+ ```ここに言語を入力
188
+ <?php
189
+
190
+ namespace App\Http\Controllers;
191
+
192
+ use Illuminate\Http\Request;
193
+ use App\Employee;
194
+ use App\Goods;
195
+
196
+ class EmployeesController extends Controller
197
+
198
+ public function update(Request $request, $id)
199
+ {
200
+ $employee = Employee::find($id);
201
+ $employee->office = $request->office;
202
+ $employee->save();
203
+
204
+ $goods = $employee->goods()->latest()->first();//(修正後)
205
+ //(修正前)$goods = Goods::find($id);
206
+ $goods->uniform = $request->uniform;
207
+ $goods->winter_clothes = $request->winter_clothes;
208
+ $goods->shoes = $request->shoes;
209
+ $goods->other = $request->other;
210
+ $goods->memo = $request->memo;
211
+ $goods->save();
212
+
213
+ return view('employee_show', compact('employee'));
214
+ }
184
215
  ```

2

文章の修正

2021/02/12 06:40

投稿

Sento__aa
Sento__aa

スコア21

title CHANGED
File without changes
body CHANGED
@@ -4,6 +4,9 @@
4
4
  ![イメージ説明](64170e5298f0853b8290371b89631b16.png)
5
5
  内容としては2つのテーブル(employeesテーブル、goodsテーブル)を一度に更新するものです。goodテーブルの情報が渡っていない(null?)が故のエラーなのでしょうか?
6
6
  調べても見出せずにいますので何卒宜しくお願いいたします。
7
+
8
+ **__Laravel バージョン 6.20.8
9
+ __**
7
10
  ### EmployeesController.php
8
11
  ```ここに言語を入力
9
12
  <?php

1

文章の修正

2021/02/12 02:52

投稿

Sento__aa
Sento__aa

スコア21

title CHANGED
File without changes
body CHANGED
@@ -133,4 +133,49 @@
133
133
  </div>
134
134
  </div>
135
135
  @endsection
136
+ ```
137
+ ## Employee.php
138
+ ```ここに言語を入力
139
+ <?php
140
+
141
+ namespace App;
142
+ use IlluminateSupportFacadesDB;
143
+ use Illuminate\Database\Eloquent\Model;
144
+
145
+ class Employee extends Model
146
+ {
147
+ protected $fillable = ['id','emlpoyee_id','employee_name','office'];
148
+
149
+ public function goods()
150
+ {
151
+ return $this->hasMany(Goods::class);
152
+ }
153
+ }
154
+
155
+ ```
156
+ ## Goods.php
157
+ ```ここに言語を入力
158
+ <?php
159
+
160
+ namespace App;
161
+
162
+ use Illuminate\Database\Eloquent\Model;
163
+
164
+ class Goods extends Model
165
+ {
166
+ protected $fillable = ['employee_id','uniform','winter_clothes','shoes','other','memo'];
167
+
168
+ protected $guarded = array('id');
169
+
170
+ public function getDate()
171
+ {
172
+ return $this->belongsTo(Employee::class);
173
+ }
174
+
175
+ public function employee()
176
+ {
177
+ return $this->belongsTo(Employee::class);
178
+ }
179
+ }
180
+
136
181
  ```