DeviceName.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace App\Models;
  3. class DeviceName extends BaseModel
  4. {
  5. public function device()
  6. {
  7. return $this->belongsTo('App\Models\Device', 'device_id');
  8. }
  9. public function getNameSpecOptions()
  10. {
  11. // $names = DeviceName::select('name as text', 'id as value')->get();
  12. // $names = $names->prepend($this->transObject(['text' => '设备名称', 'value' => '']));
  13. // foreach($names as $name) {
  14. // $specs = Spec::where('device_name_id', $name->value)->select('name as text', 'id as value')->get();
  15. // $name->specs = $specs->prepend($this->transObject(['text' => '规格型号', 'value' => '']));
  16. // }
  17. // dd($names);
  18. $names = InnerDeviceNamesModel::select('name as text', 'id as value')->get();
  19. $names = $names->prepend($this->transObject(['text' => '设备名称', 'value' => '']));
  20. // foreach($names as $name) {
  21. // $specs = Spec::where('device_name_id', $name->value)->select('name as text', 'id as value')->get();
  22. // $name->specs = $specs->prepend($this->transObject(['text' => '规格型号', 'value' => '']));
  23. // }
  24. return $names;
  25. }
  26. public function transObject($items)
  27. {
  28. return json_decode(json_encode($items));
  29. }
  30. }