/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id, Post $postModel, Images $imgModel) { $post = $postModel->getPostInfo($id); $data = $request->all(); $post->fill($data); $post->save(); $lastInsertedId = $id; if (isset($data['images'][0])) { foreach ($data['images'] as $file) { $size = $file->getSize(); //print_r($size); if ($size <= 1500000) { $destinationPath = public_path() . '/images/'; $oldaname = $file->getClientOriginalName(); $ex = $file->getClientOriginalExtension(); $filename = md5(time() . $oldaname) . '.' . $ex; //echo $destinationPath.' '.$filename.' = '.$size.' // '; $file->move($destinationPath, $filename); $imgModel->create(['user_id' => session('id'), 'post_id' => $lastInsertedId, 'name' => $filename]); } } } return redirect()->route('post.show', ['id' => $lastInsertedId]); }