PHPackages                             liar88828/laravel-schema-attributes - 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. [Database &amp; ORM](/categories/database)
4. /
5. liar88828/laravel-schema-attributes

ActiveLibrary[Database &amp; ORM](/categories/database)

liar88828/laravel-schema-attributes
===================================

PHP 8 attribute-driven schema compiler for Laravel. One schema class drives migrations, models, factories, controllers, and tests — no duplication.

v1.0.0(1mo ago)00MITPHPPHP ^8.2

Since Mar 20Pushed 1mo agoCompare

[ Source](https://github.com/liar88828/laravel-schema-attributes)[ Packagist](https://packagist.org/packages/liar88828/laravel-schema-attributes)[ Docs](https://github.com/liar88828/laravel-schema-attributes)[ RSS](/packages/liar88828-laravel-schema-attributes/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (8)Versions (2)Used By (0)

Laravel Schema Attributes
=========================

[](#laravel-schema-attributes)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ed44a97bd6a187b0da1e0c53b8f52382ddb6f3b766c7174a60be0381b7ac8983/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c69617238383832382f6c61726176656c2d736368656d612d617474726962757465732e737667)](https://packagist.org/packages/liar88828/laravel-schema-attributes)[![PHP Version](https://camo.githubusercontent.com/c9f64f714c636ba27a3bba6dfd52f98426832db1262747efa54b212d16943651/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e322d626c7565)](https://php.net)[![Laravel Version](https://camo.githubusercontent.com/5bd61ec377dc8f6b4d88d43749cfe4da6a6e79fe5f3471cc226b3c0353295a88/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d313125323025374325323031322d726564)](https://laravel.com)[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](LICENSE)

PHP 8 attribute-driven schema compiler for Laravel. **One schema class drives everything** — migrations, models, factories, controllers, and tests with no duplication.

Reverse Engineering Existing Migrations
---------------------------------------

[](#reverse-engineering-existing-migrations)

Already have a Laravel project with migrations? Import them as schemas with one command:

```
# Scan all migrations → generate schema classes in app/Schema/
php artisan schema:scan

# Scan a specific table
php artisan schema:scan create_orders_table

# Generate migration-only schemas (no EloquentModel)
php artisan schema:scan --migration

# Generate full schemas with EloquentModel
php artisan schema:scan --model

# Print to console instead of writing files
php artisan schema:scan --print

# Overwrite existing schemas
php artisan schema:scan --force
```

**Example — given this migration:**

```
Schema::create('orders', function (Blueprint $table) {
    $table->id();
    $table->foreignId('user_id')->constrained()->cascadeOnDelete();
    $table->string('status', 20)->default('pending')->index();
    $table->decimal('total', 10, 2);
    $table->timestamps();
    $table->softDeletes();
});
```

**Generated `OrderSchema.php`:**

```
#[EloquentModel(model: Order::class)]
#[Table(name: 'orders', timestamps: true, softDeletes: true)]
class OrderSchema
{
    #[PrimaryKey(type: 'bigIncrements')]
    public int $id;

    #[Column(type: 'unsignedBigInteger', index: true)]
    #[ForeignKey(references: 'id', on: 'users', onDelete: 'cascade')]
    // #[BelongsTo(related: UserSchema::class)]  ← set the related schema
    // #[Fillable]
    public int $user_id;

    #[Column(type: 'string', length: 20, default: 'pending', index: true)]
    // #[Fillable]
    public string $status;

    #[Column(type: 'decimal', precision: 10, scale: 2)]
    // #[Fillable]
    public float $total;
}
```

> After scanning, review the generated schemas and uncomment/add `#[Fillable]`, `#[Required]`, `#[Hidden]`, `#[Cast]` as needed.

Concept
-------

[](#concept)

```
#[EloquentModel(model: Article::class)]
#[Table(name: 'articles', timestamps: true, softDeletes: true)]
class ArticleSchema
{
    #[PrimaryKey(type: 'bigIncrements')]
    public int $id;

    #[Column(type: 'string', length: 191)]
    #[Fillable] #[Required] #[Min(2)] #[Max(191)]
    public string $title;

    #[Column(type: 'unsignedBigInteger')]
    #[ForeignKey(references: 'id', on: 'users', onDelete: 'cascade')]
    #[BelongsTo(related: UserSchema::class)]
    public int $user_id;
}
```

Then run **one command** to generate everything:

```
php artisan schema:refresh ArticleSchema
```

This generates:

- ✅ Migration
- ✅ Eloquent model with `$fillable`, `$hidden`, `$casts`, relations
- ✅ Factory with correct Faker calls
- ✅ PHPUnit test covering migration, model wiring, validation, persistence
- ✅ API controller with validation, Auth injection, soft delete &amp; restore

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

[](#installation)

```
composer require liar88828/laravel-schema-attributes
```

Laravel auto-discovers the service provider. No manual registration needed.

Artisan Commands
----------------

[](#artisan-commands)

CommandDescription`schema:make ArticleSchema`Create a new schema class`schema:scan`**Reverse-engineer** existing migrations → schema classes`schema:migrate ArticleSchema`Generate migration`schema:model ArticleSchema`Generate Eloquent model`schema:relations ArticleSchema`Generate relation methods`schema:factory ArticleSchema`Generate factory`schema:service ArticleSchema`Generate Service layer class`schema:controller ArticleSchema`Generate API controller`schema:test ArticleSchema`Generate PHPUnit test`schema:refresh ArticleSchema`Generate all of the aboveAvailable Attributes
--------------------

[](#available-attributes)

### Migration

[](#migration)

`#[Table]` `#[Column]` `#[PrimaryKey]` `#[ForeignKey]` `#[ForeignSchema]``#[HasOne]` `#[HasMany]` `#[BelongsTo]` `#[BelongsToMany]`

### Model

[](#model)

`#[EloquentModel]` `#[Fillable]` `#[Hidden]` `#[Cast]` `#[Appended]` `#[UsesSchema]`

### Validation

[](#validation)

`#[Required]` `#[Email]` `#[Min]` `#[Max]` `#[In]` `#[Unique]` `#[Uuid]``#[Confirmed]` `#[Regex]` `#[Numeric]`

Auth Model Example
------------------

[](#auth-model-example)

```
use Illuminate\Foundation\Auth\User;
use Illuminate\Notifications\Notifiable;
use Laravel\Fortify\TwoFactorAuthenticatable;

#[EloquentModel(
    model:  UserModel::class,
    extend: User::class,
    traits: [Notifiable::class, TwoFactorAuthenticatable::class],
)]
#[Table(name: 'users', timestamps: true, softDeletes: true)]
class UserSchema
{
    #[Column(type: 'string', length: 191, unique: true)]
    #[Fillable] #[Required] #[Email] #[Unique(table: 'users', column: 'email')]
    public string $email;

    #[Column(type: 'string')]
    #[Fillable] #[Hidden] #[Cast('hashed')] #[Required] #[Confirmed]
    public string $password;

    #[Column(type: 'rememberToken')]
    #[Hidden]
    public ?string $remember_token = null;
}
```

HasSchema Trait
---------------

[](#hasschema-trait)

Adding `use HasSchema` to your model gives you:

```
// Schema-driven validation
User::schemaValidateOrFail($request->all());

// Update validation (ignores own unique fields)
$user->schemaValidateForUpdate($request->all(), ignoreUniqueFor: ['email' => $user->id]);

// Auto $fillable, $hidden, $casts, $table from schema
// UUID primary key auto-generation
// Relation resolution from schema annotations
```

Authors &amp; Credits
---------------------

[](#authors--credits)

This package was **entirely created by AI**.

RoleAICode &amp; Architecture[Claude](https://claude.ai) (Anthropic)Helper &amp; Consultation[ChatGPT](https://chatgpt.com) (OpenAI)Human Supervisor[liar88828](https://github.com/liar88828)> 💡 This is an experiment in AI-driven open source development. Every line of code, architecture decision, bug fix, and this README was written by AI assistants guided by a human developer.

- PHP 8.2+
- Laravel 11 or 12
- [spatie/laravel-route-attributes](https://github.com/spatie/laravel-route-attributes) — installed automatically

`spatie/laravel-route-attributes` is a lightweight package (~50KB) that only depends on `illuminate/routing` which Laravel already includes. If your project already has any Spatie package installed, there is zero additional cost.

License
-------

[](#license)

MIT — see [LICENSE](LICENSE).

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance89

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

53d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/902039f698f73db3cdcffa1faef49c230a4e1f507206ad1deff60d5d01cca5fa?d=identicon)[liar88828](/maintainers/liar88828)

---

Top Contributors

[![liar88828](https://avatars.githubusercontent.com/u/108179651?v=4)](https://github.com/liar88828 "liar88828 (7 commits)")

---

Tags

laravelschemamigrationgeneratorannotationsmodelattributesphp8

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/liar88828-laravel-schema-attributes/health.svg)

```
[![Health](https://phpackages.com/badges/liar88828-laravel-schema-attributes/health.svg)](https://phpackages.com/packages/liar88828-laravel-schema-attributes)
```

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[cybercog/laravel-clickhouse

ClickHouse migrations for Laravel

163166.8k](/packages/cybercog-laravel-clickhouse)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)[dragon-code/laravel-data-dumper

Adding data from certain tables when executing the `php artisan schema:dump` console command

3418.6k](/packages/dragon-code-laravel-data-dumper)[rayvenues/eloquent-model-generator

Eloquent Model Generator

1325.2k1](/packages/rayvenues-eloquent-model-generator)

PHPackages © 2026

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