storeImage(); $newImage = auth()->user()->images()->create([ 'path' => $data['path'], 'width' => $data['width'], 'height' => $data['height'], 'location' => $data['location'], ]); return new ImageResource($newImage); } public function memos(Memo $memo) { $data = $this->storeImage(); $newImage = $memo->images()->create([ 'path' => $data['path'], 'width' => $data['width'], 'height' => $data['height'], 'location' => $data['location'], ]); return new ImageResource($newImage); } private function storeImage() { $data = request()->validate([ 'image' => 'required', 'width' => 'required', 'height' => 'required', 'location' => 'required', ]); $data['path'] = $data['image']->store('images', 'public'); Image::make($data['image']) ->fit($data['width'], $data['height']) ->save(storage_path('app/public/images/'.$data['image']->hashName())); return $data; } }