Changeset 4b7e2d3 for app/Http/Controllers/Dashboard/FoldersController.php
- Timestamp:
- 10/23/21 04:03:46 (3 years ago)
- Branches:
- develop, master
- Children:
- b39afb5
- Parents:
- c6b84df
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
app/Http/Controllers/Dashboard/FoldersController.php
rc6b84df r4b7e2d3 39 39 $folders = $foldersInDeptSort->orderBy('name', 'asc')->paginate(12); 40 40 } 41 else if ($request->query('sort') == 'no_of_files') { 42 $folders = $foldersInDeptSort->orderBy('no_of_files', 'desc')->paginate(12); 43 } 41 44 else if($request->query('sort') == 'count'){ 42 45 $total = $foldersInDeptSort->folder->files->count(); … … 52 55 else if ($request->query('sort') == 'name') { 53 56 $folders = Folder::orderBy('name', 'asc')->paginate(12); 57 } 58 else if ($request->query('sort') == 'no_of_files') { 59 $folders = Folder::orderBy('no_of_files', 'desc')->paginate(12); 54 60 } 55 61 else if ($request->query('sort') == 'important') { … … 97 103 "deptName" => $deptName, 98 104 "deptCode" => $deptCode, 99 "fileTypes" => '.' . implode(',.', explode(',', explode(':', FileType::find('1')->mimes)[1]))105 "fileTypes" => '.' . implode(',.', explode(',', FileType::find('1')->mimes)) 100 106 ]); 101 107 … … 117 123 $folder->user()->associate($user); 118 124 $folder->department()->associate($department); 125 $folder->department()->increment('no_of_folders'); 119 126 120 127 $folder->arch_id = $request->arch_id; … … 149 156 $newFile->location = $location . DIRECTORY_SEPARATOR . $fileName; 150 157 $newFile->folder()->associate($folder); 158 $newFile->folder()->increment('no_of_files'); 151 159 $newFile->save(); 152 160 } … … 155 163 Alert::flash("New folder created successfully"); 156 164 157 return redirect()-> route("dashboard.folders.index");165 return redirect()->back(); 158 166 } 159 167 … … 177 185 $department = Department::find($request->department); 178 186 179 $folder->department()-> associate($department);180 181 $oldLocation = $folder-> department->location . DIRECTORY_SEPARATOR . $folder->name;187 $folder->department()->increment('no_of_folders'); 188 189 $oldLocation = $folder->location; 182 190 183 191 $folder->name = $request->name; … … 186 194 $folder->updated_at = Carbon::now(); 187 195 188 $location = $folder->department->location . DIRECTORY_SEPARATOR . $request->name; 189 190 if ($folder->isDirty('name')) { 191 if (!Storage::disk('uploads')->has($location)) { 192 Storage::disk('uploads')->move($oldLocation, $location); 193 foreach($files as $file){ 194 $file->location = $location . DIRECTORY_SEPARATOR . $file->name; 196 $newLocation = Department::find($request->department)->location . DIRECTORY_SEPARATOR . $request->name; 197 198 if($folder->department_id != $request->department){ 199 $folder->department()->decrement('no_of_folders'); 200 if (!Storage::disk('uploads')->has($newLocation)) { 201 Storage::disk('uploads')->move($oldLocation, $newLocation); 202 foreach($files as $file) { 203 $file->location = $newLocation . DIRECTORY_SEPARATOR . $file->name; 195 204 $file->save(); 196 205 } 197 206 } 198 207 } 208 if($folder->isDirty('name')) { 209 if (!Storage::disk('uploads')->has($newLocation)) { 210 Storage::disk('uploads')->move($oldLocation, $newLocation); 211 foreach($files as $file) { 212 $file->location = $newLocation . DIRECTORY_SEPARATOR . $file->name; 213 $file->save(); 214 } 215 } 216 } 217 218 $folder->department()->associate($department); 219 220 $folder->location = $newLocation; 199 221 200 222 if ($request->has('file_item')) { 201 223 foreach ($request->file_item as $file) { 202 224 $fileName = $folder->name . '-' . uniqid() . '.' . $file->getClientOriginalExtension(); 203 $file->storeAs($ location . DIRECTORY_SEPARATOR, $fileName);225 $file->storeAs($newLocation . DIRECTORY_SEPARATOR, $fileName); 204 226 $newFile = new File(); 205 227 $newFile->name = $fileName; 206 $newFile->location = $ location . DIRECTORY_SEPARATOR . $fileName;228 $newFile->location = $newLocation . DIRECTORY_SEPARATOR . $fileName; 207 229 $newFile->folder()->associate($folder); 230 $newFile->folder()->increment('no_of_files'); 208 231 $newFile->save(); 209 232 } 210 233 } 211 234 212 $folder->location = $location;213 214 235 $folder->save(); 215 216 236 217 237 Alert::flash("Folder edited successfully"); … … 246 266 $location = $folder->department->location . DIRECTORY_SEPARATOR . $folder->name; 247 267 Storage::disk('uploads')->deleteDirectory($location); 268 $folder->department()->decrement('no_of_folders'); 248 269 Alert::flash($folder->name . " deleted successfully"); 270 return redirect()->back(); 249 271 } 250 272 Alert::flash($folder->name . " is important", "error"); 251 return redirect()-> route("dashboard.folders.index");273 return redirect()->back(); 252 274 } 253 275 … … 306 328 } 307 329 else { 308 $files = File::where('folder_id', $id)->paginate(1 0);330 $files = File::where('folder_id', $id)->paginate(12); 309 331 } 310 332 … … 317 339 "imageExt" => array("png", "jpg", "jpeg"), 318 340 "folders" => $folders, 319 "fileTypes" => '.' . implode(',.', explode(',', explode(':', FileType::find('1')->mimes)[1]))341 "fileTypes" => '.' . implode(',.', explode(',', FileType::find('1')->mimes)) 320 342 ]); 321 343 }
Note:
See TracChangeset
for help on using the changeset viewer.