InnerDevice.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\Validator;
  5. class InnerDevice extends BaseModel
  6. {
  7. public function workPoint()
  8. {
  9. return $this->belongsTo('App\Models\WorkPoint', 'work_point_id');
  10. }
  11. public function project()
  12. {
  13. return $this->belongsTo('App\Models\Project', 'project_id');
  14. }
  15. public function spec()
  16. {
  17. return $this->belongsTo('App\Models\Spec', 'spec_id');
  18. }
  19. public function device()
  20. {
  21. return $this->belongsTo('App\Models\Device', 'device_id');
  22. }
  23. public function device_name()
  24. {
  25. return $this->belongsTo('App\Models\DeviceName', 'device_name_id');
  26. }
  27. public function option()
  28. {
  29. return $this->belongsTo('App\Models\Option', 'status');
  30. }
  31. public function getValidator(Request $request, $type)
  32. {
  33. $validator = Validator::make($request->input('data'), [
  34. 'number' => 'required'
  35. ], [
  36. 'number.required' => '固定资产编号'
  37. ]);
  38. // $validator->after(function ($validator) use($request) {
  39. // if (!$request->input('device_name_id')) {
  40. // $validator->errors()->add('device_name_id', '设备名称必填');
  41. // }
  42. // if (!$request->input('spec_id')) {
  43. // $validator->errors()->add('spec_id', '规格型号必填');
  44. // }
  45. // });
  46. return $validator;
  47. }
  48. public function getStatusLabel()
  49. {
  50. return $this['option'] ? '<div style="color: ' . $this['option']['color'] . '">' . $this['option']['name'] . '</div>' : '';
  51. }
  52. public function inner_device_names(){
  53. return $this->hasOne(InnerDeviceNamesModel::class,'id','device_name_id');
  54. }
  55. }