https://github.com/jdion84/lucid
Declare database schemas inside Laravel models.
https://github.com/jdion84/lucid
database laravel lucid models schemas
Last synced: 2 months ago
JSON representation
Declare database schemas inside Laravel models.
- Host: GitHub
- URL: https://github.com/jdion84/lucid
- Owner: jdion84
- License: mit
- Created: 2024-02-16T02:04:19.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-16T02:04:44.000Z (over 2 years ago)
- Last Synced: 2025-09-09T06:40:30.777Z (10 months ago)
- Topics: database, laravel, lucid, models, schemas
- Language: PHP
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# Lucid
Declare database schemas inside Laravel models.
## Installation
Require this package via composer:
```console
composer require jdion84/lucid
```
## Usage
Create a new model class with a schema method:
```console
php artisan make:schema Post
```
Or, add a schema method to an existing model:
```php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Jdion84\Lucid\Table;
class Post extends Model
{
use HasFactory;
public function schema(Table $table)
{
$table->id();
$table->string('title')->index();
$table->text('body');
$table->timestamp('created_at');
$table->timestamp('updated_at');
}
}
```
Migrate & sync model schema methods with the database:
```console
php artisan migrate:schemas
```
## Commands
Create a new model class with a schema method:
```console
php artisan make:schema {name} {--p|pivot} {--force}
```
Migrate & sync model schema methods with the database:
```console
migrate:schemas {--f|fresh} {--s|seed} {--force}
```