]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/Images/GalleryImageController.php
Updated System CLI
[bookstack] / app / Http / Controllers / Images / GalleryImageController.php
index c3ad0b7b261fe6d5946de46eacf5f263715e7470..c01eccfee30193a5fc95f85f5a2630e190846569 100644 (file)
@@ -3,21 +3,16 @@
 namespace BookStack\Http\Controllers\Images;
 
 use BookStack\Exceptions\ImageUploadException;
+use BookStack\Http\Controllers\Controller;
 use BookStack\Uploads\ImageRepo;
 use Illuminate\Http\Request;
-use BookStack\Http\Controllers\Controller;
 use Illuminate\Validation\ValidationException;
 
 class GalleryImageController extends Controller
 {
-    protected $imageRepo;
-
-    /**
-     * GalleryImageController constructor.
-     */
-    public function __construct(ImageRepo $imageRepo)
-    {
-        $this->imageRepo = $imageRepo;
+    public function __construct(
+        protected ImageRepo $imageRepo
+    ) {
     }
 
     /**
@@ -32,22 +27,29 @@ class GalleryImageController extends Controller
         $parentTypeFilter = $request->get('filter_type', null);
 
         $imgData = $this->imageRepo->getEntityFiltered('gallery', $parentTypeFilter, $page, 24, $uploadedToFilter, $searchTerm);
-        return view('components.image-manager-list', [
-            'images' => $imgData['images'],
+
+        return view('pages.parts.image-manager-list', [
+            'images'  => $imgData['images'],
             'hasMore' => $imgData['has_more'],
         ]);
     }
 
     /**
      * Store a new gallery image in the system.
+     *
      * @throws ValidationException
      */
     public function create(Request $request)
     {
         $this->checkPermission('image-create-all');
-        $this->validate($request, [
-            'file' => $this->getImageValidationRules()
-        ]);
+
+        try {
+            $this->validate($request, [
+                'file' => $this->getImageValidationRules(),
+            ]);
+        } catch (ValidationException $exception) {
+            return $this->jsonError(implode("\n", $exception->errors()['file']));
+        }
 
         try {
             $imageUpload = $request->file('file');