From 1bd5aaaabd3a00f4570ec9eae665092169094af0 Mon Sep 17 00:00:00 2001
From: Tyler
Date: Sun, 27 Dec 2020 04:37:21 -0500
Subject: [PATCH] Save a copy of all images, update navbar, add description
---
app/Http/Controllers/MainController.php | 31 +++++++++++++++--------
resources/views/books/show.blade.php | 9 ++++++-
resources/views/partials/navbar.blade.php | 6 ++---
3 files changed, 32 insertions(+), 14 deletions(-)
diff --git a/app/Http/Controllers/MainController.php b/app/Http/Controllers/MainController.php
index 9559767..646c482 100644
--- a/app/Http/Controllers/MainController.php
+++ b/app/Http/Controllers/MainController.php
@@ -75,20 +75,31 @@ class MainController extends Controller {
$res = $service->lookup($item['barcode']);
if (!empty($res)) {
- if ($thumbnail = data_get($res, 'images.thumbnail')) {
- $file = $this->downloadFile($thumbnail);
+ if ($images = data_get($res, 'images')) {
+ $images = array_filter($images, function($item) {
+ return !empty($item);
+ });
- $attachment = $book->attach($file, [
- 'key' => 'thumbnail'
- ]);
+ foreach ($images as $key => $image) {
+ $file = $this->downloadFile($image);
- $attachment->filename = 'thumbnail.jpg';
- $attachment->save();
+ $attachment = $book->attach($file, [
+ 'key' => $key
+ ]);
+
+ $attachment->filename = $key . '.jpg';
+ $attachment->save();
+ }
}
- $book->description = $res->description;
- $book->published_date = Carbon::parse($res->published_date);
- $book->pages = $res->pages;
+ $book->description = data_get($res, 'description');
+
+ if ($date = data_get($res, 'published_date')) {
+ $book->published_date = Carbon::parse($date);
+ }
+
+ $book->pages = data_get($res, 'pages', 0);
+
$book->save();
}
}
diff --git a/resources/views/books/show.blade.php b/resources/views/books/show.blade.php
index 707662f..0018c73 100644
--- a/resources/views/books/show.blade.php
+++ b/resources/views/books/show.blade.php
@@ -11,8 +11,15 @@
@endif
- Location:
+ Location
{{ $book->location->name }}
+
+ @if (!empty($book->description))
+ Description
+
+ {{ $book->description }}
+
+ @endif
@endsection
\ No newline at end of file
diff --git a/resources/views/partials/navbar.blade.php b/resources/views/partials/navbar.blade.php
index 121d537..44d301e 100644
--- a/resources/views/partials/navbar.blade.php
+++ b/resources/views/partials/navbar.blade.php
@@ -7,13 +7,13 @@