service_id); return [ 'service_id' => 'required|exists:services,id', 'power_id' => [ Rule::requiredIf(function () use ($service) { // If service exists and is_power is true, require power_id return $service && $service->is_power; }), 'nullable', // Allow null if the condition is false 'exists:powers,id' // Validate the power_id exists in the powers table ], 'city_id' => 'required|exists:cities,id', 'phone' => 'required|numeric', 'full_name' => 'required', 'comment' => 'nullable', ]; } }