Просмотр исходного кода

Hide added devices in client > device > add

Vijayakrishnan 4 лет назад
Родитель
Сommit
d0d77e1542
2 измененных файлов с 18 добавлено и 0 удалено
  1. 8 0
      app/Models/Client.php
  2. 10 0
      resources/views/app/patient/dashboard.blade.php

+ 8 - 0
app/Models/Client.php

@@ -105,6 +105,14 @@ class Client extends Model
             ->orderBy('created_at', 'desc');
     }
 
+    public function hasDevice($_device) {
+        $count = ClientBDTDevice::where('client_id', $this->id)
+            ->where('device_id', $_device->id)
+            ->where('is_active', true)
+            ->count();
+        return !!$count;
+    }
+
     public function deviceMeasurements() {
         return $this->hasMany(ClientBDTMeasurement::class, 'client_id', 'id')
             ->orderBy('created_at', 'desc');

+ 10 - 0
resources/views/app/patient/dashboard.blade.php

@@ -15,9 +15,16 @@
                 @include('app/patient/partials/appointments')
 
                 {{-- devices --}}
+                <?php $availableDevices = 0; ?>
+                @foreach($devices as $device)
+                    @if(!$patient->hasDevice($device))
+                        <?php $availableDevices++; ?>
+                    @endif
+                @endforeach
                 <div class="mt-2 pb-1">
                     <div class="d-flex align-items-center mb-2 py-2 border-top border-bottom">
                         <h6 class="my-0 font-weight-bold text-secondary">Devices</h6>
+                        @if($availableDevices > 0)
                         <span class="mx-2 text-secondary">|</span>
                         <span moe>
                             <a start show>Add</a>
@@ -28,9 +35,11 @@
                                     <select name="deviceUid" class="form-control form-control-sm">
                                         <option value=""> --select-- </option>
                                         @foreach($devices as $device)
+                                            @if(!$patient->hasDevice($device))
                                             <option value="{{$device->uid}}">
                                                 {{$device->category}} (IMEI: {{$device->imei}})
                                             </option>
+                                            @endif
                                         @endforeach
                                     </select>
                                 </div>
@@ -56,6 +65,7 @@
                                 </div>
                             </form>
                         </span>
+                        @endif
                     </div>
                     <table class="table table-sm border-0 my-0 mx-2">
                         <tbody>