- $this->checkPermission('image-create');
- $imageUpload = $request->file('file');
- $name = str_replace(' ', '-', $imageUpload->getClientOriginalName());
- $storageName = substr(sha1(time()), 0, 10) . '-' . $name;
- $imagePath = '/uploads/images/' . Date('Y-m-M') . '/';
- $storagePath = public_path() . $imagePath;
- $fullPath = $storagePath . $storageName;
- while (file_exists($fullPath)) {
- $storageName = substr(sha1(rand()), 0, 3) . $storageName;
- $fullPath = $storagePath . $storageName;
- }
- $imageUpload->move($storagePath, $storageName);
- // Create and save image object
- $this->image->name = $name;
- $this->image->url = $imagePath . $storageName;
- $this->image->created_by = Auth::user()->id;
- $this->image->updated_by = Auth::user()->id;
- $this->image->save();
- $this->image->thumbnail = $this->getThumbnail($this->image, 150, 150);
- return response()->json($this->image);
+ $this->checkPermission('image-create-all');
+ $image = $this->imageRepo->getById($id);
+ $thumbnailUrl = $this->imageRepo->getThumbnail($image, $width, $height, $crop == 'false');
+ return response()->json(['url' => $thumbnailUrl]);