Browse Source

Fixed filter bug

jquino 5 years ago
parent
commit
64c7faaef0

+ 2
- 0
app/Http/Middleware/SetDept.php View File

15
      */
15
      */
16
     public function handle($request, Closure $next)
16
     public function handle($request, Closure $next)
17
     {
17
     {
18
+        // dump($request);
18
         if ($request->has('f')) {
19
         if ($request->has('f')) {
19
             $data = $request->validate(['f' => 'regex:/[df]/']);
20
             $data = $request->validate(['f' => 'regex:/[df]/']);
20
             $request->session()->put('filter', $data['f']);
21
             $request->session()->put('filter', $data['f']);
34
             $default_dept_id = \App\Department::where('name', '=', 'BIOL')->first()->id;
35
             $default_dept_id = \App\Department::where('name', '=', 'BIOL')->first()->id;
35
             $request->session()->put('department', $default_dept_id);
36
             $request->session()->put('department', $default_dept_id);
36
         }
37
         }
38
+        // dump($request->session());
37
         return $next($request);
39
         return $next($request);
38
     }
40
     }
39
 }
41
 }

+ 1
- 1
database/migrations/2019_07_07_183013_create_departments_table.php View File

15
     {
15
     {
16
         Schema::create('departments', function (Blueprint $table) {
16
         Schema::create('departments', function (Blueprint $table) {
17
             $table->bigIncrements('id');
17
             $table->bigIncrements('id');
18
+            $table->string('code')->nullable();
18
             $table->string('name')->nullable();
19
             $table->string('name')->nullable();
19
-            $table->string('title')->nullable();
20
             $table->unsignedBigInteger('faculty_id');
20
             $table->unsignedBigInteger('faculty_id');
21
 
21
 
22
             $table->foreign('faculty_id')->references('id')->on('faculties');
22
             $table->foreign('faculty_id')->references('id')->on('faculties');

+ 1
- 1
resources/views/dashboard/register.blade.php View File

102
                                                     </div>
102
                                                     </div>
103
                                                     <div class="mdc-checkbox__ripple"></div>
103
                                                     <div class="mdc-checkbox__ripple"></div>
104
                                                 </div>
104
                                                 </div>
105
-                                                <label for="checkbox-d-{{ $loop->index }}">{{ $department->title ?: $department->name }}</label>
105
+                                                <label for="checkbox-d-{{ $loop->index }}">{{ $department->name ?: $department->code }}</label>
106
                                             </div>
106
                                             </div>
107
                                         </div>
107
                                         </div>
108
                                     @endforeach
108
                                     @endforeach

+ 8
- 4
resources/views/layouts/app.blade.php View File

44
                     </li>
44
                     </li>
45
                     <li class="nav-item dropdown">
45
                     <li class="nav-item dropdown">
46
                         @php
46
                         @php
47
-                            $department = \App\Department::find(Request()->session()->get('department'));
47
+                            switch(Request()->session()->get('filter')) {
48
+                                case 'f': $division = App\Faculty::find(Request()->session()->get('faculty')); break;
49
+                                case 'd': $division = App\Department::find(Request()->session()->get('department')); break;
50
+                                default: break;
51
+                            }
48
                         @endphp
52
                         @endphp
49
                         <a class="nav-link dropdown-toggle mdc-typography--body1" href="#" data-toggle="dropdown">
53
                         <a class="nav-link dropdown-toggle mdc-typography--body1" href="#" data-toggle="dropdown">
50
-                            {{ $department->title ?: $department->name ?? 'Departamento' }} <span class="caret"></span>
54
+                            {{ $division->name ?: $division->code ?? 'Departamento' }} <span class="caret"></span>
51
                         </a>
55
                         </a>
52
                         <ul class="dropdown-menu">
56
                         <ul class="dropdown-menu">
53
                             @foreach (App\Faculty::orderBy('name')->get() as $faculty)
57
                             @foreach (App\Faculty::orderBy('name')->get() as $faculty)
54
-                                @if (!$faculty->departments->isEmpty())
58
+                                @if ($faculty->departments->isNotEmpty())
55
                                     <li class="dropdown-submenu">
59
                                     <li class="dropdown-submenu">
56
                                         <a class="dropdown-item dropdown-toggle mdc-typography--body1" href="#" data-toggle="dropdown">{{ $faculty->name }}</a>
60
                                         <a class="dropdown-item dropdown-toggle mdc-typography--body1" href="#" data-toggle="dropdown">{{ $faculty->name }}</a>
57
                                         <ul class="dropdown-menu">
61
                                         <ul class="dropdown-menu">
58
                                             @foreach ($faculty->departments as $dept)
62
                                             @foreach ($faculty->departments as $dept)
59
                                                 <li class="mdc-typography--body2">
63
                                                 <li class="mdc-typography--body2">
60
                                                     <a class="dropdown-item" href="{{ url()->current() }}?f=d&dept={{ $dept->id }}">
64
                                                     <a class="dropdown-item" href="{{ url()->current() }}?f=d&dept={{ $dept->id }}">
61
-                                                        {{ $dept->title ?: $dept->name }}
65
+                                                        {{ $dept->name ?: $dept->code }}
62
                                                     </a>
66
                                                     </a>
63
                                                 </li>
67
                                                 </li>
64
                                             @endforeach
68
                                             @endforeach