Index: app/Http/Controllers/Dashboard/DepartmentsController.php
===================================================================
--- app/Http/Controllers/Dashboard/DepartmentsController.php	(revision bd9e8e32f60b76ec300f4c312ea24835f0a7608d)
+++ app/Http/Controllers/Dashboard/DepartmentsController.php	(revision e6c1f87d9981de7492736e12f9cc56fc273c8e2a)
@@ -36,4 +36,6 @@
         $department->code = $request->code;
 
+        $len = Storage::disk('local')->path('');
+
         if(!Storage::disk('local')->has('Departments/' . $request->code)){
             Storage::disk('local')->makeDirectory('Departments/' . $request->code);
@@ -41,5 +43,5 @@
 
         $department->user_id = auth()->id();
-        $department->location = '/Departments/' . $request->code;
+        $department->location =  Storage::disk('local')->path('') . 'Departments/' . $request->code;
 
         $department->save();
@@ -65,8 +67,6 @@
         $department->name = $request->name;
         $department->code = $request->code;
-        $department->updated_at = Carbon::now();;
 
-        $path = '/Departments/' . $request->code;
-        $department->location = $path;
+        $department->location =  Storage::disk('local')->path('') . 'Departments/' . $request->code;
 
         $files = Storage::allFiles($oldDepartmentCode);
Index: app/Http/Controllers/Dashboard/DocumentsController.php
===================================================================
--- app/Http/Controllers/Dashboard/DocumentsController.php	(revision bd9e8e32f60b76ec300f4c312ea24835f0a7608d)
+++ app/Http/Controllers/Dashboard/DocumentsController.php	(revision e6c1f87d9981de7492736e12f9cc56fc273c8e2a)
@@ -17,11 +17,69 @@
     public function index(Request $request)
     {
+        $queries = explode(" ", $request->search);
+        $result = collect();
+
+        foreach ($queries as $query) {
+            $result->push(Document::where("arch_id", "like", "%{$query}%")->orWhere("name", "like", "%{$query}%")->get());
+        }
+
+        $result = $result->flatten();
+
+
         if ($request->query('id')) {
-            $documents = Document::where('department_id', $request->query('id'))->get();
-        } else {
-            $documents = Document::all();
+
+            $documentsInDeptSort = Document::with('department')->when($request->has('id'), function($query) use ($request) {
+                $query->where('department_id', $request->query('id'));
+            });
+
+            if($request->query('sort') == 'newest') {
+                $documents = $documentsInDeptSort->orderBy('created_at', 'desc')->paginate(20);
+            }
+            else if($request->query('sort') == 'name') {
+                $documents = $documentsInDeptSort->orderBy('name', 'asc')->paginate(20);
+            }
+            else{
+                $documents = Document::where('department_id', $request->query('id'))->paginate(20);
+            }
+        }
+        else {
+            if($request->query('sort') == 'newest') {
+                $documents = Document::orderBy('created_at', 'desc')->paginate(20);
+            }
+            else if($request->query('sort') == 'name') {
+                $documents = Document::orderBy('name', 'asc')->paginate(20);
+            }
+            else if($request->query('sort') == 'important'){
+                $documents = Document::where('is_important', true)->paginate(20);
+            }
+            else if($request->query('sort') == 'recent') {
+               $documents = Document::orderBy('created_at', 'desc')->paginate(20);
+            }
+            else if($request->query('search')){
+                $result = collect();
+
+                foreach ($queries as $query) {
+                    $result->push(Document::where("arch_id", "like", "%{$query}%")->orWhere("name", "like", "%{$query}%")->get());
+                }
+                $result = $result->flatten();
+                $documents = $result;
+            }
+            else
+            {
+                $documents = Document::paginate(20);
+            }
         }
 
         $departments = Department::all();
+
+        $diskTotal = disk_total_space('/');
+        $diskTotalSize = $diskTotal / 1073741824;
+
+        $diskFree  = disk_free_space('/');
+        $used = $diskTotal - $diskFree;
+
+        $diskUsedSize = $used / 1073741824;
+        $diskUse1 = round(100 - (($diskUsedSize / $diskTotalSize) * 100));
+        $diskUse = round(100 - ($diskUse1)) . '%';
 
         return view("dashboard.documents.index")->with([
@@ -30,5 +88,11 @@
             "departments" => $departments,
             "docsCount" => Department::withCount('document')->get(),
-            'totalDocs' => Document::all()->count()
+            "totalDocs" => Document::all()->count(),
+            "countImportant" => Document::where('is_important', true)->get()->count(),
+            "diskTotal" => $diskTotal,
+            "diskTotalSize" => $diskTotalSize,
+            "diskUse" => $diskUse,
+            "diskUsedSize" => $diskUsedSize
+
         ]);
 
@@ -40,4 +104,38 @@
             "departments" => Department::all()
         ]);
+    }
+
+    public function store(DocumentRequest $request, UploadService $uploadService)
+    {
+        $document = new Document();
+        $user = auth()->user();
+        $department = Department::find($request->department);
+
+        $document->user()->associate($user);
+        $document->department()->associate($department);
+
+        $document->arch_id = $request->arch_id;
+        $document->name = $request->name;
+        $document->description = $request->description;
+
+        if (!Storage::disk('local')->has($document->department()->pluck('location')->join("") . '/' . $request->arch_id)) {
+            Storage::disk('local')->makeDirectory($document->department()->pluck('location')->join("") . '/' . $request->arch_id);
+        }
+
+        $documentFile = $uploadService->upload(File::class, [
+            "file_item" => $request->file_item,
+        ], "link", true);
+
+        $document->save();
+
+        foreach ($documentFile as $df) {
+            $file = File::find($df);
+            $file->document()->associate($document);
+            $file->save();
+        }
+
+        Alert::flash("New document created successfully");
+
+        return redirect()->route("dashboard.documents.index");
     }
 
@@ -73,37 +171,46 @@
     }
 
-    public function store(DocumentRequest $request, UploadService $uploadService)
-    {
-        $document = new Document();
-        $user = auth()->user();
-        $department = Department::find($request->department);
-
-        $document->user()->associate($user);
-        $document->department()->associate($department);
-
-        $document->arch_id = $request->arch_id;
-        $document->name = $request->name;
-        $document->description = $request->description;
-
-        if (!Storage::disk('local')->has($document->department()->pluck('location')->join("") . '/' . $request->arch_id)) {
-            Storage::disk('local')->makeDirectory($document->department()->pluck('location')->join("") . '/' . $request->arch_id);
-        }
-
-        $documentFile = $uploadService->upload(File::class, [
-            "file_item" => $request->file_item,
-        ], "link", true);
-
+    public function toggleImportant($id)
+    {
+        $document = Document::find($id);
+        $document->is_important = !$document->is_important;
         $document->save();
 
-        foreach ($documentFile as $df) {
-            $file = File::find($df);
-            $file->document()->associate($document);
-            $file->save();
-        }
-
-        Alert::flash("New document created successfully");
-
+        if($document->is_important==true)
+        Alert::flash("Document marked as important successfully");
+        else
+            Alert::flash("Document marked as not important successfully");
+
+        return redirect()->back();
+    }
+
+    public function search(Request $request)
+    {
+        $queries = explode(" ", $request->q);
+        $result = collect();
+
+        foreach ($queries as $query) {
+            $result->push(Document::where("arch_id", "like", "%{$query}%")->orWhere("name", "like", "%{$query}%")->get());
+        }
+
+        $result = $result->flatten();
+
+        $departments = Department::all();
+
+        return view("dashboard.documents.search")
+            ->with("searchQuery", $request->q)
+            ->with("results", $result)
+            ->with("departments", $departments)
+            ->with("countImportant", Document::where('is_important', true)->get()->count());
+    }
+
+    public function destroy($id)
+    {
+        $document = Document::find($id);
+        if (auth()->user()->hasPermission("delete_all_posts")) {
+            $document->delete();
+            Alert::flash($document->name . " deleted successfully");
+        }
         return redirect()->route("dashboard.documents.index");
     }
-
 }
Index: app/Http/Controllers/Dashboard/SettingsController.php
===================================================================
--- app/Http/Controllers/Dashboard/SettingsController.php	(revision bd9e8e32f60b76ec300f4c312ea24835f0a7608d)
+++ app/Http/Controllers/Dashboard/SettingsController.php	(revision e6c1f87d9981de7492736e12f9cc56fc273c8e2a)
@@ -3,4 +3,5 @@
 namespace App\Http\Controllers\Dashboard;
 
+use App\Helpers\Alert;
 use App\Http\Requests\Dashboard\EmailSettingsRequest;
 use App\Http\Requests\Dashboard\PasswordSettingsRequest;
@@ -10,4 +11,7 @@
 use App\Notifications\VerifyNewEmail;
 use Carbon\Carbon;
+use Illuminate\Contracts\Validation\Validator;
+use Illuminate\Http\Request;
+use Illuminate\Validation\ValidationException;
 
 class SettingsController extends Controller
@@ -17,5 +21,5 @@
         return view("dashboard.settings.index")->with([
             "user" => auth()->user(),
-            "adminAndEditors" => User::where("role_id", 1)->orWhere("role_id", 2)->get(),
+            "adminAndReferents" => User::where("role_id", 1)->orWhere("role_id", 2)->get(),
             "active_tab" => "account"
         ]);
@@ -24,5 +28,4 @@
     public function updateUsername(UsernameSettingsRequest $request)
     {
-        if ($request->validated()) {
             $user = auth()->user();
             $user->username = $request->username;
@@ -33,21 +36,16 @@
 
             return redirect()->route("auth.loginShow");
-        } else {
-            return back()->with(['active_tab' => 'security']);
-        }
-
-        dd('no');
     }
 
-    public function updatePassword(PasswordSettingsRequest $request)
+    public function updatePassword(UsernameSettingsRequest $request)
     {
-        $user = auth()->user();
-        $user->password = bcrypt($request->password);
-        $user->save();
+            $user = auth()->user();
+            $user->password = bcrypt($request->password);
+            $user->save();
 
-        auth()->logout();
-        session()->flush();
+            auth()->logout();
+            session()->flush();
 
-        return redirect()->route("auth.loginShow");
+            return redirect()->route("auth.loginShow");
     }
 
