Skip to content

Commit d4ba7e6

Browse files
Customizado controller Gallerys
1 parent 01570a6 commit d4ba7e6

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

app/Http/Controllers/Admin/Gallerys/GallerysController.php

+11-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
class GallerysController extends Controller
1111
{
12+
const UPLOAD_PATH = 'gallerys/';
13+
const UPLOAD_ROUTE = 'admin.gallerys.upload';
14+
1215
/**
1316
* Display a listing of the resource.
1417
*
@@ -56,8 +59,8 @@ public function store(Request $request)
5659
$gallery->save();
5760

5861
$user = \Auth::User();
59-
$path_from = 'gallerys/temp-'.$user->id.'/';
60-
$path_to = 'gallerys/'.$gallery->id;
62+
$path_from = self::UPLOAD_PATH.'temp-'.$user->id.'/';
63+
$path_to = self::UPLOAD_PATH.$gallery->id;
6164

6265
if (\Storage::disk('uploads')->exists($path_from)) {
6366
\Storage::disk('uploads')->move($path_from, $path_to);
@@ -132,7 +135,7 @@ public function destroy(Request $request)
132135
// tem que ser um foreach porque é um array de galerias
133136
foreach ($request->gallerys as $id) {
134137
// Checamos se o diretório existe
135-
$path = 'gallerys/'.$id;
138+
$path = self::UPLOAD_PATH.$id;
136139

137140
// Deletamos o diretório da imagem
138141
if (\Storage::disk('uploads')->exists($path)) {
@@ -160,21 +163,21 @@ public function upload(Request $request, $id = null)
160163
}
161164

162165
$config = [
163-
'script_url' => '/admin/gallerys/upload/'.$path.'/',
164-
'upload_dir' => base_path().'/public/uploads/gallerys/'.$path.'/',
165-
'upload_url' => url('/').'/uploads/gallerys/'.$path.'/',
166+
'script_url' => route(self::UPLOAD_ROUTE,$path),
167+
'upload_dir' => base_path().'/public/uploads/'.self::UPLOAD_PATH.$path.'/',
168+
'upload_url' => url('/').'/uploads/'.self::UPLOAD_PATH.$path.'/',
166169
'delete_type' => 'GET',
167170
];
168171

169172

170173
// Deletamos a imagem por GET
171174
if (isset($request->file)) {
172-
$file = 'gallerys/'.$path.'/'.$request->file;
175+
$file = self::UPLOAD_PATH.$path.'/'.$request->file;
173176
if (\Storage::disk('uploads')->has($file)) {
174177
\Storage::disk('uploads')->delete($file);
175178
}
176179

177-
$thumb = 'gallerys/'.$path.'/thumbnail/'.$request->file;
180+
$thumb = self::UPLOAD_PATH.$path.'/thumbnail/'.$request->file;
178181
if (\Storage::disk('uploads')->has($thumb)) {
179182
\Storage::disk('uploads')->delete($thumb);
180183
}

0 commit comments

Comments
 (0)