paginate(10); return view('admin.machines.index', compact('machines')); } /** * Show the form for creating a new resource. */ public function create() { return view('admin.machines.create'); } /** * Store a newly created resource in storage. */ public function store(Request $request) { $validated = $request->validate([ 'name' => 'required|string|max:255', 'location' => 'nullable|string|max:255', 'status' => 'required|in:online,offline,error', 'temperature' => 'nullable|numeric', 'firmware_version' => 'nullable|string|max:50', ]); Machine::create($validated); return redirect()->route('admin.machines.index') ->with('success', '機台建立成功'); } /** * Display the specified resource. */ public function show(Machine $machine) { return view('admin.machines.show', compact('machine')); } /** * Show the form for editing the specified resource. */ public function edit(Machine $machine) { return view('admin.machines.edit', compact('machine')); } /** * Update the specified resource in storage. */ public function update(Request $request, Machine $machine) { $validated = $request->validate([ 'name' => 'required|string|max:255', 'location' => 'nullable|string|max:255', 'status' => 'required|in:online,offline,error', 'temperature' => 'nullable|numeric', 'firmware_version' => 'nullable|string|max:50', ]); $machine->update($validated); return redirect()->route('admin.machines.index') ->with('success', '機台更新成功'); } /** * Remove the specified resource from storage. */ public function destroy(Machine $machine) { $machine->delete(); return redirect()->route('admin.machines.index') ->with('success', '機台已刪除'); } }