MeasuringMachineController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\MeasuringMachine;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Facades\Validator;
  6. class MeasuringMachineController extends Controller
  7. {
  8. /**
  9. * Display a listing of the resource.
  10. *
  11. * @return \Illuminate\Http\Response
  12. */
  13. public function index()
  14. {
  15. $measuringMachines=MeasuringMachine::orderBy('id','DESC')->paginate(50);
  16. return view('maintenance.measuringMachine.index',['measuringMachines'=>$measuringMachines]);
  17. }
  18. /**
  19. * Show the form for creating a new resource.
  20. *
  21. * @return \Illuminate\Http\Response
  22. */
  23. public function create()
  24. {
  25. return view('maintenance.measuringMachine.create');
  26. }
  27. /**
  28. * Store a newly created resource in storage.
  29. *
  30. * @param \Illuminate\Http\Request $request
  31. * @return \Illuminate\Http\Response
  32. */
  33. public function store(Request $request)
  34. {
  35. $id=false;
  36. $this->validator($request,$id)->validate();
  37. MeasuringMachine::create($request->input());
  38. return redirect('maintenance/measuringMachine')->with('successTip','新设备“'.$request->input('name').'”添加成功');
  39. }
  40. /**
  41. * Display the specified resource.
  42. *
  43. * @param \App\MeasuringMachine $measuringMachine
  44. * @return \Illuminate\Http\Response
  45. */
  46. public function show(MeasuringMachine $measuringMachine)
  47. {
  48. //
  49. }
  50. /**
  51. * Show the form for editing the specified resource.
  52. *
  53. * @param \App\MeasuringMachine $measuringMachine
  54. * @return \Illuminate\Http\Response
  55. */
  56. public function edit(MeasuringMachine $measuringMachine)
  57. {
  58. //
  59. }
  60. /**
  61. * Update the specified resource in storage.
  62. *
  63. * @param \Illuminate\Http\Request $request
  64. * @param \App\MeasuringMachine $measuringMachine
  65. * @return \Illuminate\Http\Response
  66. */
  67. public function update(Request $request, MeasuringMachine $measuringMachine)
  68. {
  69. //
  70. }
  71. /**
  72. * Remove the specified resource from storage.
  73. *
  74. * @param \App\MeasuringMachine $measuringMachine
  75. * @return \Illuminate\Http\Response
  76. */
  77. public function destroy(MeasuringMachine $measuringMachine)
  78. {
  79. //
  80. }
  81. public function validator(Request $request,$id){
  82. if ($id){$code=$id;}
  83. $validator=Validator::make($request->input(),[
  84. 'name'=>['required','max:50'],
  85. 'code'=>['required','max:50',isset($code)?"unique:measuring_machines,code,$code":'unique:measuring_machines,code'],
  86. ],[
  87. 'required'=>':attribute 为必填项',
  88. 'unique'=>':attribute 已存在',
  89. ],[
  90. 'name'=>'设备名',
  91. 'code'=>'设备代码',
  92. ]);
  93. return $validator;
  94. }
  95. }