Index: app/Http/Controllers/Dashboard/DocumentsController.php
===================================================================
--- app/Http/Controllers/Dashboard/DocumentsController.php	(revision d795fa6d6f9dce899a9ce38b85983b77c28a7e19)
+++ app/Http/Controllers/Dashboard/DocumentsController.php	(revision bd9e8e32f60b76ec300f4c312ea24835f0a7608d)
@@ -17,10 +17,7 @@
     public function index(Request $request)
     {
-        if($request->department) {
-            $documents = Document::with('department')->where('department', function ($query) {
-                $query->where('id', $request->department)->get();
-            });
-        }
-        else{
+        if ($request->query('id')) {
+            $documents = Document::where('department_id', $request->query('id'))->get();
+        } else {
             $documents = Document::all();
         }
@@ -68,5 +65,4 @@
         $document->arch_id = $request->arch_id;
         $document->description = $request->description;
-        $document->updated_at = $request->Carbon::now();;
 
         $document->save();
@@ -90,5 +86,5 @@
         $document->description = $request->description;
 
-        if(!Storage::disk('local')->has($document->department()->pluck('location')->join("") . '/' . $request->arch_id)){
+        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);
         }
@@ -106,5 +102,5 @@
         }
 
-            Alert::flash("New document created successfully");
+        Alert::flash("New document created successfully");
 
         return redirect()->route("dashboard.documents.index");
Index: app/Http/Controllers/Dashboard/SettingsController.php
===================================================================
--- app/Http/Controllers/Dashboard/SettingsController.php	(revision d795fa6d6f9dce899a9ce38b85983b77c28a7e19)
+++ app/Http/Controllers/Dashboard/SettingsController.php	(revision bd9e8e32f60b76ec300f4c312ea24835f0a7608d)
@@ -18,4 +18,5 @@
             "user" => auth()->user(),
             "adminAndEditors" => User::where("role_id", 1)->orWhere("role_id", 2)->get(),
+            "active_tab" => "account"
         ]);
     }
@@ -23,17 +24,18 @@
     public function updateUsername(UsernameSettingsRequest $request)
     {
-//        if($request->validated()){
-//        $user = auth()->user();
-//        $user->username = $request->username;
-//        $user->save();
-//
-//        auth()->logout();
-//        session()->flush();
-//
-//        return redirect()->route("auth.loginShow");
-//        }
-//        else {
-            return back()->withInput(['tab'=>'security']);
-       // }
+        if ($request->validated()) {
+            $user = auth()->user();
+            $user->username = $request->username;
+            $user->save();
+
+            auth()->logout();
+            session()->flush();
+
+            return redirect()->route("auth.loginShow");
+        } else {
+            return back()->with(['active_tab' => 'security']);
+        }
+
+        dd('no');
     }
 
Index: app/Http/Requests/Dashboard/DocumentRequest.php
===================================================================
--- app/Http/Requests/Dashboard/DocumentRequest.php	(revision d795fa6d6f9dce899a9ce38b85983b77c28a7e19)
+++ app/Http/Requests/Dashboard/DocumentRequest.php	(revision bd9e8e32f60b76ec300f4c312ea24835f0a7608d)
@@ -16,5 +16,5 @@
     public function authorize()
     {
-        if($this->isMethod("patch")) {
+        if ($this->isMethod("patch")) {
             $document = Document::find($this->route("id"));
             return auth()->user()->hasPermission("edit_all_documents") || ($document->user->id == auth()->user()->id);
@@ -33,5 +33,14 @@
 
         $rules = [
-            "arch_id" => "required|min:10|max:255",
+            "arch_id" => [
+                "required",
+                function($attribute, $value, $fail) {
+                    $arch_id = $this->request->get('arch_id');
+                    $deptId = explode('/', $arch_id)[0];
+                    if ($deptId !== $this->request->get('department')) {
+                        $fail("Dept id error");
+                    }
+                }
+            ],
             "name" => "required|min:10|max:255",
             "department" => "required|integer|exists:departments,id",
@@ -39,8 +48,8 @@
         ];
 
-        if($this->isMethod("patch")) {
+        if ($this->isMethod("patch")) {
             $fileRules = [
                 "file_item.*" => "mimes:jpg,jpeg,png|max:4096"
-                ];
+            ];
         } else {
             $fileRules = [
Index: app/Http/Requests/Dashboard/UsernameSettingsRequest.php
===================================================================
--- app/Http/Requests/Dashboard/UsernameSettingsRequest.php	(revision d795fa6d6f9dce899a9ce38b85983b77c28a7e19)
+++ app/Http/Requests/Dashboard/UsernameSettingsRequest.php	(revision bd9e8e32f60b76ec300f4c312ea24835f0a7608d)
@@ -4,4 +4,6 @@
 
 use Illuminate\Foundation\Http\FormRequest;
+use Illuminate\Contracts\Validation\Validator;
+use Illuminate\Validation\ValidationException;
 
 class UsernameSettingsRequest extends FormRequest
@@ -28,3 +30,15 @@
         ];
     }
+
+    protected function failedValidation(Validator $validator)
+    {
+        $response = redirect()
+            ->route('dashboard.settings.index')
+            ->with(['active_tab' => 'security'])
+            ->withErrors($validator);
+
+        throw (new ValidationException($validator, $response))
+            ->errorBag($this->errorBag)
+            ->redirectTo($this->getRedirectUrl());
+    }
 }
