X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/04f37e21e2d1552ed537b35faba37ec53971a5bc..refs/pull/3570/head:/app/Http/Controllers/BookshelfController.php diff --git a/app/Http/Controllers/BookshelfController.php b/app/Http/Controllers/BookshelfController.php index 9a7f78a85..a294bf731 100644 --- a/app/Http/Controllers/BookshelfController.php +++ b/app/Http/Controllers/BookshelfController.php @@ -83,15 +83,15 @@ class BookshelfController extends Controller public function store(Request $request) { $this->checkPermission('bookshelf-create-all'); - $this->validate($request, [ + $validated = $this->validate($request, [ 'name' => ['required', 'string', 'max:255'], 'description' => ['string', 'max:1000'], 'image' => array_merge(['nullable'], $this->getImageValidationRules()), + 'tags' => ['array'], ]); $bookIds = explode(',', $request->get('books', '')); - $shelf = $this->bookshelfRepo->create($request->all(), $bookIds); - $this->bookshelfRepo->updateCoverImage($shelf, $request->file('image', null)); + $shelf = $this->bookshelfRepo->create($validated, $bookIds); return redirect($shelf->getUrl()); } @@ -160,16 +160,21 @@ class BookshelfController extends Controller { $shelf = $this->bookshelfRepo->getBySlug($slug); $this->checkOwnablePermission('bookshelf-update', $shelf); - $this->validate($request, [ + $validated = $this->validate($request, [ 'name' => ['required', 'string', 'max:255'], 'description' => ['string', 'max:1000'], 'image' => array_merge(['nullable'], $this->getImageValidationRules()), + 'tags' => ['array'], ]); + if ($request->has('image_reset')) { + $validated['image'] = null; + } elseif (array_key_exists('image', $validated) && is_null($validated['image'])) { + unset($validated['image']); + } + $bookIds = explode(',', $request->get('books', '')); - $shelf = $this->bookshelfRepo->update($shelf, $request->all(), $bookIds); - $resetCover = $request->has('image_reset'); - $this->bookshelfRepo->updateCoverImage($shelf, $request->file('image', null), $resetCover); + $shelf = $this->bookshelfRepo->update($shelf, $validated, $bookIds); return redirect($shelf->getUrl()); }