Changeset 13ff930 for app/Http/Controllers
- Timestamp:
- 10/25/21 13:09:52 (3 years ago)
- Branches:
- develop, master
- Children:
- 55c9542
- Parents:
- 507ade0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
app/Http/Controllers/Dashboard/DepartmentsController.php
r507ade0 r13ff930 8 8 use App\Models\Department; 9 9 use App\Models\File; 10 use App\Models\Folder; 10 11 use App\Models\User; 11 12 use App\Notifications\NewDepartmentCreated; … … 119 120 public function downloadAll() 120 121 { 121 try { 122 $departments = Department::all(); 123 $flag=false; 124 125 foreach ($departments as $department) { 126 if($department->no_of_folders > 0) { 127 $folders = Folder::where('department_id', $department->id)->get(); 128 } 129 foreach ($folders as $folder){ 130 if($folder->no_of_files > 0){ 131 $flag=true; 132 break; 133 } 134 } 135 } 136 137 if($flag) { 122 138 $zip_file = Storage::disk('uploads')->path('Departments.zip'); 123 139 $zip = new \ZipArchive(); … … 141 157 $headers = array('Content-Type' => 'application/octet-stream'); 142 158 $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . '- Departments.zip'; 143 }144 catch(\Exception $e){145 //abort(403, "No files found"); 146 Alert::flash("All departments are empty", "warning");147 return redirect()->back();148 }149 return response()->download($zip_file, $zip_new_name, $headers);159 return response()->download($zip_file, $zip_new_name, $headers); 160 } 161 162 else { 163 Alert::flash("All departments are empty", "warning"); 164 return redirect()->back(); 165 } 150 166 } 151 167 152 168 public function downloadDepartment($id) 153 169 { 154 try {155 170 $department = Department::find($id); 171 $folders = Folder::where('department_id', $id)->get(); 172 $flag = false; 173 174 foreach($folders as $folder){ 175 if($folder->no_of_files > 0) 176 $flag=true; 177 break; 178 } 179 180 if($flag) { 156 181 $zip_file=Storage::disk('uploads')->path('Department.zip'); 157 182 $zip = new \ZipArchive(); … … 174 199 $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . '- Departments.zip'; 175 200 return response()->download($zip_file, $zip_new_name, $headers); 176 } 177 catch(\Exception $e){ 178 //abort(403, "No files found"); 179 Alert::flash("This department has no files", "warning"); 180 return redirect()->back(); 181 } 201 } 202 else { 203 Alert::flash("This department has no files", "warning"); 204 return redirect()->back(); 205 } 182 206 } 183 207 }
Note:
See TracChangeset
for help on using the changeset viewer.