Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
nyumbani-validation
nyumbani/essentials
claude-code
laravel
essentials
nyumbani

Invoke when validating input in a Nyumbani app: Form Requests, the phone rules KenyanNumberValid and PhoneNumberValid, the CleanName cast for names, friendly attribute names, or password rules. Skip for several forms on one page (see nyumbani-error-bags) and for sign-in (see nyumbani-auth).

Install
php artisan boost:add-skill nyumbani/essentials

Save this content to: .claude/skills/nyumbani-validation/SKILL.md

# Nyumbani Validation

Validate in a Form Request, never inline in a controller. Keep each field's rules in a named variable and give friendly names with `attributes()`.
```php
use Illuminate\Foundation\Http\FormRequest;
use Nyumbani\Essentials\Rules\KenyanNumberValid;

class StoreCustomerRequest extends FormRequest
{
    public function rules(): array
    {
        $name = ['required', 'string', 'max:255'];
        $phone = ['required', new KenyanNumberValid];

        return ['name' => $name, 'phone' => $phone];
    }

    public function attributes(): array
    {
        return ['phone' => 'phone number'];
    }
}
```

## Rules
Both live in `Nyumbani\Essentials\Rules`.

| Rule | Accepts |
| --- | --- |
| `KenyanNumberValid` | A Kenyan mobile: optional `0`, `254` or `+254`, then `7xx` or `10x`/`11x`, then six more digits. `0712345678`, `254712345678`, `+254712345678`, `712345678` and `0110123456` pass; `071234567` (a digit short) and `0212345678` (a landline) fail. |
| `PhoneNumberValid` | An international number of 7 to 15 digits with an optional leading `+`. |

Use `KenyanNumberValid` for anything that gets an SMS or an M-Pesa prompt. Normalise a number before sending with the helper the sending package provides (`daraja_phone()` for Daraja; the message builder for Messaging).

## CleanName cast
Collapses repeated spaces and title-cases a name on the way in; reading is unchanged. It only cleans non-empty strings.
```php
use Nyumbani\Essentials\Casts\CleanName;

protected function casts(): array
{
    return ['name' => CleanName::class];
}

//  "  jane    WANJIRU " is stored as "Jane Wanjiru"
```
Do not clean names in the controller or the request: the cast does it for every write.

## Passwords
Passwords need at least 8 characters, through `Password::defaults()`, which Essentials sets. Use `Password::defaults()` in your own rules rather than `Password::min()`.

## Messages
Validation messages and flash texts are lang keys, never hard-coded sentences (see the lang rule). Several forms on one page each need their own error bag: see nyumbani-error-bags.

Nyumbani Validation

Validate in a Form Request, never inline in a controller. Keep each field's rules in a named variable and give friendly names with attributes().

use Illuminate\Foundation\Http\FormRequest;
use Nyumbani\Essentials\Rules\KenyanNumberValid;

class StoreCustomerRequest extends FormRequest
{
    public function rules(): array
    {
        $name = ['required', 'string', 'max:255'];
        $phone = ['required', new KenyanNumberValid];

        return ['name' => $name, 'phone' => $phone];
    }

    public function attributes(): array
    {
        return ['phone' => 'phone number'];
    }
}

Rules

Both live in Nyumbani\Essentials\Rules.

Rule Accepts
KenyanNumberValid A Kenyan mobile: optional 0, 254 or +254, then 7xx or 10x/11x, then six more digits. 0712345678, 254712345678, +254712345678, 712345678 and 0110123456 pass; 071234567 (a digit short) and 0212345678 (a landline) fail.
PhoneNumberValid An international number of 7 to 15 digits with an optional leading +.

Use KenyanNumberValid for anything that gets an SMS or an M-Pesa prompt. Normalise a number before sending with the helper the sending package provides (daraja_phone() for Daraja; the message builder for Messaging).

CleanName cast

Collapses repeated spaces and title-cases a name on the way in; reading is unchanged. It only cleans non-empty strings.

use Nyumbani\Essentials\Casts\CleanName;

protected function casts(): array
{
    return ['name' => CleanName::class];
}

//  "  jane    WANJIRU " is stored as "Jane Wanjiru"

Do not clean names in the controller or the request: the cast does it for every write.

Passwords

Passwords need at least 8 characters, through Password::defaults(), which Essentials sets. Use Password::defaults() in your own rules rather than Password::min().

Messages

Validation messages and flash texts are lang keys, never hard-coded sentences (see the lang rule). Several forms on one page each need their own error bag: see nyumbani-error-bags.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator