Changeset e6c1f87 for app/Http/Controllers
- Timestamp:
- 10/18/21 19:54:18 (3 years ago)
- Branches:
- develop, master
- Children:
- b9c4a92
- Parents:
- bd9e8e3
- Location:
- app/Http/Controllers/Dashboard
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
app/Http/Controllers/Dashboard/DepartmentsController.php
rbd9e8e3 re6c1f87 36 36 $department->code = $request->code; 37 37 38 $len = Storage::disk('local')->path(''); 39 38 40 if(!Storage::disk('local')->has('Departments/' . $request->code)){ 39 41 Storage::disk('local')->makeDirectory('Departments/' . $request->code); … … 41 43 42 44 $department->user_id = auth()->id(); 43 $department->location = '/Departments/' . $request->code;45 $department->location = Storage::disk('local')->path('') . 'Departments/' . $request->code; 44 46 45 47 $department->save(); … … 65 67 $department->name = $request->name; 66 68 $department->code = $request->code; 67 $department->updated_at = Carbon::now();;68 69 69 $path = '/Departments/' . $request->code; 70 $department->location = $path; 70 $department->location = Storage::disk('local')->path('') . 'Departments/' . $request->code; 71 71 72 72 $files = Storage::allFiles($oldDepartmentCode); -
app/Http/Controllers/Dashboard/DocumentsController.php
rbd9e8e3 re6c1f87 17 17 public function index(Request $request) 18 18 { 19 $queries = explode(" ", $request->search); 20 $result = collect(); 21 22 foreach ($queries as $query) { 23 $result->push(Document::where("arch_id", "like", "%{$query}%")->orWhere("name", "like", "%{$query}%")->get()); 24 } 25 26 $result = $result->flatten(); 27 28 19 29 if ($request->query('id')) { 20 $documents = Document::where('department_id', $request->query('id'))->get(); 21 } else { 22 $documents = Document::all(); 30 31 $documentsInDeptSort = Document::with('department')->when($request->has('id'), function($query) use ($request) { 32 $query->where('department_id', $request->query('id')); 33 }); 34 35 if($request->query('sort') == 'newest') { 36 $documents = $documentsInDeptSort->orderBy('created_at', 'desc')->paginate(20); 37 } 38 else if($request->query('sort') == 'name') { 39 $documents = $documentsInDeptSort->orderBy('name', 'asc')->paginate(20); 40 } 41 else{ 42 $documents = Document::where('department_id', $request->query('id'))->paginate(20); 43 } 44 } 45 else { 46 if($request->query('sort') == 'newest') { 47 $documents = Document::orderBy('created_at', 'desc')->paginate(20); 48 } 49 else if($request->query('sort') == 'name') { 50 $documents = Document::orderBy('name', 'asc')->paginate(20); 51 } 52 else if($request->query('sort') == 'important'){ 53 $documents = Document::where('is_important', true)->paginate(20); 54 } 55 else if($request->query('sort') == 'recent') { 56 $documents = Document::orderBy('created_at', 'desc')->paginate(20); 57 } 58 else if($request->query('search')){ 59 $result = collect(); 60 61 foreach ($queries as $query) { 62 $result->push(Document::where("arch_id", "like", "%{$query}%")->orWhere("name", "like", "%{$query}%")->get()); 63 } 64 $result = $result->flatten(); 65 $documents = $result; 66 } 67 else 68 { 69 $documents = Document::paginate(20); 70 } 23 71 } 24 72 25 73 $departments = Department::all(); 74 75 $diskTotal = disk_total_space('/'); 76 $diskTotalSize = $diskTotal / 1073741824; 77 78 $diskFree = disk_free_space('/'); 79 $used = $diskTotal - $diskFree; 80 81 $diskUsedSize = $used / 1073741824; 82 $diskUse1 = round(100 - (($diskUsedSize / $diskTotalSize) * 100)); 83 $diskUse = round(100 - ($diskUse1)) . '%'; 26 84 27 85 return view("dashboard.documents.index")->with([ … … 30 88 "departments" => $departments, 31 89 "docsCount" => Department::withCount('document')->get(), 32 'totalDocs' => Document::all()->count() 90 "totalDocs" => Document::all()->count(), 91 "countImportant" => Document::where('is_important', true)->get()->count(), 92 "diskTotal" => $diskTotal, 93 "diskTotalSize" => $diskTotalSize, 94 "diskUse" => $diskUse, 95 "diskUsedSize" => $diskUsedSize 96 33 97 ]); 34 98 … … 40 104 "departments" => Department::all() 41 105 ]); 106 } 107 108 public function store(DocumentRequest $request, UploadService $uploadService) 109 { 110 $document = new Document(); 111 $user = auth()->user(); 112 $department = Department::find($request->department); 113 114 $document->user()->associate($user); 115 $document->department()->associate($department); 116 117 $document->arch_id = $request->arch_id; 118 $document->name = $request->name; 119 $document->description = $request->description; 120 121 if (!Storage::disk('local')->has($document->department()->pluck('location')->join("") . '/' . $request->arch_id)) { 122 Storage::disk('local')->makeDirectory($document->department()->pluck('location')->join("") . '/' . $request->arch_id); 123 } 124 125 $documentFile = $uploadService->upload(File::class, [ 126 "file_item" => $request->file_item, 127 ], "link", true); 128 129 $document->save(); 130 131 foreach ($documentFile as $df) { 132 $file = File::find($df); 133 $file->document()->associate($document); 134 $file->save(); 135 } 136 137 Alert::flash("New document created successfully"); 138 139 return redirect()->route("dashboard.documents.index"); 42 140 } 43 141 … … 73 171 } 74 172 75 public function store(DocumentRequest $request, UploadService $uploadService) 76 { 77 $document = new Document(); 78 $user = auth()->user(); 79 $department = Department::find($request->department); 80 81 $document->user()->associate($user); 82 $document->department()->associate($department); 83 84 $document->arch_id = $request->arch_id; 85 $document->name = $request->name; 86 $document->description = $request->description; 87 88 if (!Storage::disk('local')->has($document->department()->pluck('location')->join("") . '/' . $request->arch_id)) { 89 Storage::disk('local')->makeDirectory($document->department()->pluck('location')->join("") . '/' . $request->arch_id); 90 } 91 92 $documentFile = $uploadService->upload(File::class, [ 93 "file_item" => $request->file_item, 94 ], "link", true); 95 173 public function toggleImportant($id) 174 { 175 $document = Document::find($id); 176 $document->is_important = !$document->is_important; 96 177 $document->save(); 97 178 98 foreach ($documentFile as $df) { 99 $file = File::find($df); 100 $file->document()->associate($document); 101 $file->save(); 102 } 103 104 Alert::flash("New document created successfully"); 105 179 if($document->is_important==true) 180 Alert::flash("Document marked as important successfully"); 181 else 182 Alert::flash("Document marked as not important successfully"); 183 184 return redirect()->back(); 185 } 186 187 public function search(Request $request) 188 { 189 $queries = explode(" ", $request->q); 190 $result = collect(); 191 192 foreach ($queries as $query) { 193 $result->push(Document::where("arch_id", "like", "%{$query}%")->orWhere("name", "like", "%{$query}%")->get()); 194 } 195 196 $result = $result->flatten(); 197 198 $departments = Department::all(); 199 200 return view("dashboard.documents.search") 201 ->with("searchQuery", $request->q) 202 ->with("results", $result) 203 ->with("departments", $departments) 204 ->with("countImportant", Document::where('is_important', true)->get()->count()); 205 } 206 207 public function destroy($id) 208 { 209 $document = Document::find($id); 210 if (auth()->user()->hasPermission("delete_all_posts")) { 211 $document->delete(); 212 Alert::flash($document->name . " deleted successfully"); 213 } 106 214 return redirect()->route("dashboard.documents.index"); 107 215 } 108 109 216 } -
app/Http/Controllers/Dashboard/SettingsController.php
rbd9e8e3 re6c1f87 3 3 namespace App\Http\Controllers\Dashboard; 4 4 5 use App\Helpers\Alert; 5 6 use App\Http\Requests\Dashboard\EmailSettingsRequest; 6 7 use App\Http\Requests\Dashboard\PasswordSettingsRequest; … … 10 11 use App\Notifications\VerifyNewEmail; 11 12 use Carbon\Carbon; 13 use Illuminate\Contracts\Validation\Validator; 14 use Illuminate\Http\Request; 15 use Illuminate\Validation\ValidationException; 12 16 13 17 class SettingsController extends Controller … … 17 21 return view("dashboard.settings.index")->with([ 18 22 "user" => auth()->user(), 19 "adminAnd Editors" => User::where("role_id", 1)->orWhere("role_id", 2)->get(),23 "adminAndReferents" => User::where("role_id", 1)->orWhere("role_id", 2)->get(), 20 24 "active_tab" => "account" 21 25 ]); … … 24 28 public function updateUsername(UsernameSettingsRequest $request) 25 29 { 26 if ($request->validated()) {27 30 $user = auth()->user(); 28 31 $user->username = $request->username; … … 33 36 34 37 return redirect()->route("auth.loginShow"); 35 } else {36 return back()->with(['active_tab' => 'security']);37 }38 39 dd('no');40 38 } 41 39 42 public function updatePassword( PasswordSettingsRequest $request)40 public function updatePassword(UsernameSettingsRequest $request) 43 41 { 44 $user = auth()->user();45 $user->password = bcrypt($request->password);46 $user->save();42 $user = auth()->user(); 43 $user->password = bcrypt($request->password); 44 $user->save(); 47 45 48 auth()->logout();49 session()->flush();46 auth()->logout(); 47 session()->flush(); 50 48 51 return redirect()->route("auth.loginShow");49 return redirect()->route("auth.loginShow"); 52 50 } 53 51
Note:
See TracChangeset
for help on using the changeset viewer.