$this->meal->photos ], ); } public function updatedTmpMealPhotos($values) { /* dd($values); */ $newPhotos = collect($values)->take(3); $attachmentGroup = "meal_photos"; $userId = Auth::user()->id; $filePath = $attachmentGroup . "/" . $userId . "/" . $this->meal->id; $publicFilePath = "public/" . $filePath; foreach($newPhotos as $photo) { $curPhoto = $photo ->storePublicly($publicFilePath); $fileData = [ 'user_id' => $userId, 'group' => $attachmentGroup, 'original_name' => $photo->getClientOriginalName(), 'size' => $photo->getSize(), ]; $newFile = UserAttachment::updateOrCreate( $fileData, [ 'path' => preg_replace("/public\//xi", "/storage/", $curPhoto), 'specs' => json_encode( [ 'ext' => $photo->extension(), 'original_path' => $curPhoto, ] ) ] ); $newFile->save(); $this->meal->photos()->attach($newFile->id); } } }