PHPackages                             kjjd84/lucid - 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. kjjd84/lucid

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

kjjd84/lucid
============

Declare database schemas &amp; factory definitions inside Laravel models.

1.2.6(2mo ago)085↓50%MITPHP

Since Dec 13Pushed 2mo agoCompare

[ Source](https://github.com/kjjd84/lucid)[ Packagist](https://packagist.org/packages/kjjd84/lucid)[ RSS](/packages/kjjd84-lucid/feed)WikiDiscussions main Synced 1mo ago

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

Lucid
=====

[](#lucid)

Declare database schemas &amp; factory definitions inside Laravel models.

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

[](#installation)

Require Lucid via composer:

```
composer require kjjd84/lucid
```

Replace the default `User` model in new apps:

```
php artisan lucid:model User --force
```

Usage
-----

[](#usage)

### Using the `lucid:model` Command

[](#using-the-lucidmodel-command)

Create a new Lucid model:

```
php artisan lucid:model Post
```

### Manually Adding Schemas &amp; Definitions

[](#manually-adding-schemas--definitions)

You may also add `schema` and `definition` methods to existing models:

```
namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Kjjd84\Lucid\Database\Blueprint;

class Post extends Model
{
    use HasFactory;

    public function schema(Blueprint $table): void
    {
        $table->id();
        $table->string('title');
        $table->text('body');
        $table->timestamp('created_at');
        $table->timestamp('updated_at');
    }

    public function definition(): array
    {
        return [
            'title' => fake()->sentence(),
            'body' => fake()->paragraph(),
        ];
    }
}
```

If adding methods manually, make sure to create a Lucid factory for the model:

```
php artisan lucid:factory Post
```

### Defining Multiple Schemas &amp; Definitions

[](#defining-multiple-schemas--definitions)

Define multiple schemas &amp; definitions by appending `Schema` / `Definition`:

```
namespace App\Traits;

use App\Models\Tenant;
use Kjjd84\Lucid\Database\Blueprint;

trait HasTenant
{
    public function tenantSchema(Blueprint $table): void
    {
        $table->integer('tenant_id')->index();
    }

    public function tenantDefinition(): array
    {
        return [
            'tenant_id' => Tenant::factory(),
        ];
    }
}
```

Migrating &amp; Syncing
-----------------------

[](#migrating--syncing)

Migrate &amp; sync schemas with the database:

```
php artisan lucid:migrate
```

This runs traditional migrations first, then syncs schema methods automatically.

Commands
--------

[](#commands)

### `lucid:model`

[](#lucidmodel)

Create a new Lucid model.

```
php artisan lucid:model {name} {--force} {--p|pivot} {--r|resource}
```

- `name`: the model name
- `--force`: Create the model even if it already exists
- `--pivot` or `-p`: Create a pivot instead of a regular model
- `--resource` or `-r`: Create a Filament resource for the model

### `lucid:factory`

[](#lucidfactory)

Create a new Lucid factory.

```
php artisan lucid:factory {name} {--force}
```

- `name`: the model name for the factory
- `--force`: Create the factory even if it already exists

### `lucid:migrate`

[](#lucidmigrate)

Migrate &amp; sync schemas with the database.

```
php artisan lucid:migrate {--force} {--f|fresh} {--s|seed}
```

- `--force`: Force the operation to run when in production
- `--fresh` or `-f`: Drop all tables from the database first
- `--seed` or `-s`: Re-run seeders when migrations are complete

Notes
-----

[](#notes)

- This package only works with `sqlite`, `mysql`, &amp; `pgsql` PDO drivers
- Renaming columns will result data loss unless renamed before running `lucid:migrate`
- Lucid definition methods only work with a `LucidFactory`
- All columns (except `id`) are nullable by default
- All models are unguarded via `Model::unguard()`

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance85

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

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

Every ~22 days

Recently: every ~2 days

Total

21

Last Release

77d ago

### Community

Maintainers

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

---

Top Contributors

[![kjjd84](https://avatars.githubusercontent.com/u/181235578?v=4)](https://github.com/kjjd84 "kjjd84 (23 commits)")

---

Tags

databasedefinitionsfactorylaravellucidmodelsschemaslaravelfactorydatabasemodelsdefinitionslucidschemas

### Embed Badge

![Health badge](/badges/kjjd84-lucid/health.svg)

```
[![Health](https://phpackages.com/badges/kjjd84-lucid/health.svg)](https://phpackages.com/packages/kjjd84-lucid)
```

###  Alternatives

[gearbox-solutions/eloquent-filemaker

A package for getting FileMaker records as Eloquent models in Laravel

6454.8k2](/packages/gearbox-solutions-eloquent-filemaker)[laravel-doctrine/fluent

A fluent PHP mapping driver for Doctrine2.

43430.3k13](/packages/laravel-doctrine-fluent)[awssat/laravel-sync-migration

Laravel tool helps to sync migrations without refreshing the database

10923.2k](/packages/awssat-laravel-sync-migration)

PHPackages © 2026

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