Save a copy of all images, update navbar, add description
This commit is contained in:
@ -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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user