PHPackages                             elbgoods/laravel-swiss-canton-rule - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. elbgoods/laravel-swiss-canton-rule

AbandonedArchivedLibrary[Validation &amp; Sanitization](/categories/validation)

elbgoods/laravel-swiss-canton-rule
==================================

Laravel validation rules for swiss cantons.

1.0.0(4y ago)32.1k11MITPHPPHP ^7.4 || ^8.0

Since Feb 17Pushed 4y ago2 watchersCompare

[ Source](https://github.com/elbgoods/laravel-swiss-canton-rule)[ Packagist](https://packagist.org/packages/elbgoods/laravel-swiss-canton-rule)[ Docs](https://github.com/elbgoods/laravel-swiss-canton-rule)[ RSS](/packages/elbgoods-laravel-swiss-canton-rule/feed)WikiDiscussions master Synced yesterday

READMEChangelog (7)Dependencies (5)Versions (8)Used By (1)

Laravel Swiss Canton Validation Rules
=====================================

[](#laravel-swiss-canton-validation-rules)

[![Latest Version](https://camo.githubusercontent.com/ed5900cb6180ba3ea6a0ffc2e3d81916970c9133ac4a1b05200041d46ecb7c99/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c62676f6f64732f6c61726176656c2d73776973732d63616e746f6e2d72756c652e7376673f6c6162656c3d52656c65617365267374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/elbgoods/laravel-swiss-canton-rule)[![MIT License](https://camo.githubusercontent.com/7f2e9472eeee7c4a2f1b478411e15761bfb5658d6a20f18083e86211907c7383/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f656c62676f6f64732f6c61726176656c2d73776973732d63616e746f6e2d72756c652e7376673f6c6162656c3d4c6963656e736526636f6c6f723d626c7565267374796c653d666f722d7468652d6261646765)](https://github.com/elbgoods/laravel-swiss-canton-rule/blob/master/LICENSE)[![Offset Earth](https://camo.githubusercontent.com/adde0313ccccfe3a49df6bd5075d1391cd7ee9e58c373c83dc9eff84e87ce181/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54726565776172652d2546302539462538432542332d677265656e3f7374796c653d666f722d7468652d62616467652663616368655365636f6e64733d363030)](https://plant.treeware.earth/elbgoods/laravel-swiss-canton-rule)

[![GitHub Workflow Status](https://camo.githubusercontent.com/9871660d3c400e767a5ddf5f810f7727d3fc58c9d3a28a248ef28b122de651b5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f656c62676f6f64732f6c61726176656c2d73776973732d63616e746f6e2d72756c652f72756e2d74657374733f6c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/elbgoods/laravel-swiss-canton-rule/actions?query=workflow%3Arun-tests)[![StyleCI](https://camo.githubusercontent.com/39dcfe1f2dbf4c4fe1d01004ebad80c25f59664ada3f12387fafc1b9378cb31a/68747470733a2f2f7374796c6563692e696f2f7265706f732f3234313039373535362f736869656c64)](https://styleci.io/repos/241097556)[![Total Downloads](https://camo.githubusercontent.com/24968bb6fbd6419d5677269a968be694d2bbe16a5b9d6b0799be408b324ca128/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656c62676f6f64732f6c61726176656c2d73776973732d63616e746f6e2d72756c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/elbgoods/laravel-swiss-canton-rule)

This package provides multiple validation rules to validate swiss cantons. It's based on [wnx/php-swiss-cantons](https://github.com/stefanzweifel/php-swiss-cantons).

Installation
------------

[](#installation)

At first you have to add this package to your `composer.json`:

```
composer require elbgoods/laravel-swiss-canton-rule
```

After this you can publish the package translation files to adjust the error messages:

```
php artisan vendor:publish --provider="Elbgoods\SwissCantonRule\SwissCantonRuleServiceProvider" --tag=lang
```

Usage
-----

[](#usage)

### General

[](#general)

This package provides a basic `SwissCantonRule` which you can use. All more specific rules only extend this rule with a predefined `format`.

```
use Elbgoods\SwissCantonRule\Rules\SwissCantonRule;

$rule = new SwissCantonRule(SwissCantonRule::FORMAT_ABBREVIATION);
```

By default the rule requires a value - if you want to accept `null` values you can use the `nullable()` method or set the `$required` parameter to `false`.

```
use Elbgoods\SwissCantonRule\Rules\SwissCantonRule;

$rule = new SwissCantonRule(SwissCantonRule::FORMAT_ABBREVIATION, null, false);
$rule->nullable();
```

### Abbreviation

[](#abbreviation)

```
use Elbgoods\SwissCantonRule\Rules\SwissCantonAbbreviationRule;

$rule = new SwissCantonAbbreviationRule();
```

### Zip-code

[](#zip-code)

```
use Elbgoods\SwissCantonRule\Rules\SwissCantonZipCodeRule;

$rule = new SwissCantonZipCodeRule();
```

### Name

[](#name)

The name rule has a special property - the `locale`. By default it's `null` so it allows all known canton names in all languages. But you can set a wanted locale, in this case it will validate using the given locale.

```
use Elbgoods\SwissCantonRule\Rules\SwissCantonNameRule;

$rule = new SwissCantonNameRule(); // all languages
$rule = new SwissCantonNameRule('de'); // german only
```

Because the package is based on `wnx/php-swiss-cantons` we only support the languages available in this package.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Versioning
----------

[](#versioning)

This package follows [semantic versioning](https://semver.org/).

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

Please see [SECURITY](SECURITY.md) for details.

Credits
-------

[](#credits)

- [Tom Witkowski](https://github.com/Gummibeer)
- [All Contributors](https://github.com/elbgoods/laravel-swiss-canton-rule/graphs/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

Treeware
--------

[](#treeware)

You're free to use this package, but if it makes it to your production environment we would highly appreciate you buying or planting the world a tree.

It’s now common knowledge that one of the best tools to tackle the climate crisis and keep our temperatures from rising above 1.5C is to [plant trees](https://www.bbc.co.uk/news/science-environment-48870920). If you contribute to my forest you’ll be creating employment for local families and restoring wildlife habitats.

You can buy trees at [offset.earth/treeware](https://plant.treeware.earth/elbgoods/laravel-swiss-canton-rule)

Read more about Treeware at

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 84.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~80 days

Recently: every ~119 days

Total

7

Last Release

1791d ago

Major Versions

0.6.0 → 1.0.02021-06-16

PHP version history (2 changes)0.1.0PHP ^7.4

0.6.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/eb5d60f7dd33ef3680490f11b3cd461b0c7a5dcddfe69d57fb1f6a3406be4570?d=identicon)[Gummibeer](/maintainers/Gummibeer)

![](https://www.gravatar.com/avatar/33a11c820ca1801a2b0cc065786385f9a1746ae02d1a120102ea7fc7f545eeb7?d=identicon)[Elbgoods](/maintainers/Elbgoods)

---

Top Contributors

[![Gummibeer](https://avatars.githubusercontent.com/u/6187884?v=4)](https://github.com/Gummibeer "Gummibeer (27 commits)")[![stefanzweifel](https://avatars.githubusercontent.com/u/1080923?v=4)](https://github.com/stefanzweifel "stefanzweifel (3 commits)")[![eisfeuer](https://avatars.githubusercontent.com/u/12658491?v=4)](https://github.com/eisfeuer "eisfeuer (1 commits)")[![jamesmills](https://avatars.githubusercontent.com/u/557096?v=4)](https://github.com/jamesmills "jamesmills (1 commits)")

---

Tags

cantonlaravelphp-swiss-cantonsswisstreewarevalidationvalidation-ruleslaravelvalidationswisscantons

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/elbgoods-laravel-swiss-canton-rule/health.svg)

```
[![Health](https://phpackages.com/badges/elbgoods-laravel-swiss-canton-rule/health.svg)](https://phpackages.com/packages/elbgoods-laravel-swiss-canton-rule)
```

###  Alternatives

[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M107](/packages/propaganistas-laravel-phone)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3853.3M1](/packages/axlon-laravel-postal-code-validation)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[laravel-validation-rules/credit-card

Validate credit card number, expiration date, cvc

2412.2M5](/packages/laravel-validation-rules-credit-card)[galahad/laravel-addressing

Laravel package providing addressing functionality

70316.6k](/packages/galahad-laravel-addressing)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
