validate([ 'name' => 'required|string|max:255', 'email' => 'nullable|email|max:255', 'phone' => 'nullable|string|max:50', 'whatsapp_number' => 'nullable|string|max:20', 'address' => 'nullable|string', 'contact_person' => 'nullable|string|max:255', 'tax_number' => 'nullable|string|max:50', 'credit_limit' => 'nullable|numeric|min:0', 'is_active' => 'nullable|boolean', ]); $validated['is_active'] = (bool) $request->input('is_active', 1); Customer::create($validated); return redirect()->route('sales.customers.index')->with('success', 'Customer created successfully.'); } public function show(Customer $customer) { return view('sales.customers.show', compact('customer')); } public function edit(Customer $customer) { return view('sales.customers.edit', compact('customer')); } public function update(Request $request, Customer $customer) { $validated = $request->validate([ 'name' => 'required|string|max:255', 'email' => 'nullable|email|max:255', 'phone' => 'nullable|string|max:50', 'whatsapp_number' => 'nullable|string|max:20', 'address' => 'nullable|string', 'contact_person' => 'nullable|string|max:255', 'tax_number' => 'nullable|string|max:50', 'credit_limit' => 'nullable|numeric|min:0', 'is_active' => 'nullable|boolean', ]); $validated['is_active'] = (bool) $request->input('is_active', 0); $customer->update($validated); return redirect()->route('sales.customers.index')->with('success', 'Customer updated successfully.'); } public function destroy(Customer $customer) { $customer->delete(); return redirect()->route('sales.customers.index')->with('success', 'Customer deleted successfully.'); } }