Skip to content

Releases: harris21/laravel-aegis

v0.1.1

06 Jun 10:47
9365ba5

Choose a tag to compare

Patch release.

  • ValueObjectRule now returns a clean validation message when a field gets the wrong type (an array or object where a scalar Value Object is expected) instead of leaking a raw TypeError. Value Objects that accept arrays or mixed keep working, and a validationMessage() override still takes precedence. Thanks @zigzagdev for the first community contribution.
  • Added Laravel Pint and a CI lint gate that fails the build on style violations.

v0.1.0

19 May 21:23

Choose a tag to compare

Initial release. Scaffolding and validation helpers for Laravel Value Objects.

Scaffolder

php artisan make:value-object Email --rule=email --normalize=lower --cast=Order.email generates:

  • A Value Object class: final readonly, validated, normalized, with Castable, Stringable, and JsonSerializable wired up. ComparesCastableAttributes::compare() is added when --normalize is set, so Eloquent dirty-checking treats casing-equivalent values as equal.
  • A Pest test stub.
  • A patched target model: the cast line gets inserted into the model's casts() method, indented to match the existing entries.

Curated --rule values: email, url, ip, uuid, alpha_num, alpha, numeric, regex:PATTERN.

Composable normalizers: lower, upper, trim. Combine with commas (--normalize=trim,lower).

--method=name:returnType (repeatable) drops an empty method stub for your domain logic.

--type validates against PHP primitives plus any existing class.

--cast=Billing/Invoice.email resolves to nested model paths.

--dry-run, --force, --no-test, --namespace=NS round out the flag surface.

When the target model uses a shape we can't safely modify (parent::casts() merges, no casts() method), Aegis falls back to printing the snippet for you to paste manually. The VO and test files still get written.

FormRequest bridge

use Illuminate\Validation\Rule;
use HarrisRafto\Aegis\Concerns\ResolvesValueObjects;

class StoreUserRequest extends FormRequest
{
    use ResolvesValueObjects;

    public function rules(): array
    {
        return [
            'email' => ['required', Rule::valueObject(Email::class)],
        ];
    }
}

// In your controller:
$email = $request->valueObject('email'); // Email instance, already validated

Rule::valueObject(...) uses any Value Object class as a Laravel validation rule by running its constructor. ResolvesValueObjects gives the FormRequest a valueObject($key) accessor that returns the already-validated instance — no second construction.

Codebase auditor

php artisan vo:scan walks your Eloquent models and migrations, flags column names matching common patterns (email, url, uuid, ip, slug, country_code, currency_code, status, money), and prints the make:value-object invocation for each candidate. A coverage statistic at the end tells you how much of your codebase is already wrapped.

--path, --migrations-path, --no-cast, --json configure the walk and the output.

Customisation

php artisan vendor:publish --tag=aegis-stubs

Copies value-object.stub and value-object-test.stub into stubs/aegis.*.stub, where the generators look first before falling back to the package's bundled copies. Edit them to match your project's house style.

--tag=aegis-config publishes the config file. --tag=aegis publishes both.

Requirements

  • PHP 8.3+
  • Laravel 13

Built by @harrisrafto for Laravel Live Japan 2026.