From 67782e30e85455329010e87f08bc0d4425649902 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Fri, 19 May 2017 13:17:27 +0100 Subject: [PATCH] Add check that photos key exists before trying to do something with it --- app/Services/NoteService.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/app/Services/NoteService.php b/app/Services/NoteService.php index 09dbb1c9..83cc7f2d 100644 --- a/app/Services/NoteService.php +++ b/app/Services/NoteService.php @@ -76,18 +76,20 @@ class NoteService } */ //add support for media uploaded as URLs - foreach ($data['photo'] as $photo) { - // check the media was uploaded to my endpoint, and use path - if (starts_with($photo, config('filesystems.disks.s3.url'))) { - $path = substr($photo, strlen(config('filesystems.disks.s3.url'))); - $media = Media::where('path', ltrim($path, '/'))->firstOrFail(); - } else { - $media = Media::firstOrNew(['path' => $photo]); - // currently assuming this is a photo from Swarm - $media->type = 'image'; - $media->save(); + if (array_key_exists('photo', $data)) { + foreach ($data['photo'] as $photo) { + // check the media was uploaded to my endpoint, and use path + if (starts_with($photo, config('filesystems.disks.s3.url'))) { + $path = substr($photo, strlen(config('filesystems.disks.s3.url'))); + $media = Media::where('path', ltrim($path, '/'))->firstOrFail(); + } else { + $media = Media::firstOrNew(['path' => $photo]); + // currently assuming this is a photo from Swarm + $media->type = 'image'; + $media->save(); + } + $note->media()->save($media); } - $note->media()->save($media); } $note->save();