InnerDevice.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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_id')) {
  40. $validator->errors()->add('device_id', '设备类型必填');
  41. }
  42. if (!$request->input('device_name_id')) {
  43. $validator->errors()->add('device_name_id', '设备名称必填');
  44. }
  45. if (!$request->input('spec_id')) {
  46. $validator->errors()->add('spec_id', '规格型号必填');
  47. }
  48. });
  49. return $validator;
  50. }
  51. }