Skip to content

Commit d0e7b28

Browse files
author
ahmadhussnain
committed
used auto upload functions inside CategoryController.php
1 parent 57ad266 commit d0e7b28

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

app/Http/Controllers/Api/CategoryController.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,17 @@ private function storeUpdateCategoryPhoto(StoreCategoryRequest $request, Categor
8080
{
8181
// Update data
8282
$data = $request->all();
83-
8483
if ($request->hasFile('photo')) {
8584

86-
// If there is a photo(jpg|jpeg|png) inside the request
85+
// During update: If there is a photo(jpg|jpeg|png) inside the request
8786
// then it means we have to delete the old photo from the file system
8887
// and replace with the new one.
8988
if ($deleteOldFile && $category->photo) {
90-
// Returns trailing name component of path
91-
$oldPath = basename($category->photo); // 6546dgfgfdgfg.jpg
92-
Storage::delete('/public/categories/'.$oldPath);
89+
$this->categoryFileDelete($category->photo);
9390
}
9491

9592
$file = $request->file('photo');
96-
/*
97-
// Old way to store images
98-
$filename = 'categories/' . uniqid() . '.' . $file->extension(); // categories/6546dgfgfdgfg.jpg
99-
$file->storePubliclyAs('public', $filename); // Store inside filesystem categories/6546dgfgfdgfg.jpg
100-
*/
101-
102-
// New way
103-
$fileDirectory = '/categories/';
104-
$fileName = uniqid().'.'. $file->extension();
105-
Storage::putFileAs('public'.$fileDirectory, $file, $fileName);
106-
107-
$data['photo'] = URL::to(''.'storage'.$fileDirectory.$fileName, [], $this->isSecureScheme()); // http://lara8api.test/storage/categories/6546dgfgfdgfg.jpg
93+
$data['photo'] = $this->categoryFileStore($file);
10894
}
10995
return $data;
11096
}

0 commit comments

Comments
 (0)