
laravel-model-migrations
by tanaka-mambinge
SKILL.md
name: laravel-model-migrations description: Explain how this repo (and others) reason about defining migrations directly on models, keeping the commands aligned after changes. license: MIT compatibility:
- opencode
- claude
- antigravity
- copilot metadata: audience: developers
Overview
This repo relies on laravel-auto/migrations (v1.0.4, see composer.json) so we can keep most tables in sync by declaring their schema on the model itself. The package lives alongside the standard Laravel migration workflow: php artisan migrate still runs first, then php artisan migrate:auto compares the models’ migration() definitions against the database and applies the delta.
Installation & Setup
- Run
composer install(already included in this repo and enforced via post-install scripts) to installlaravel-auto/migrationsalongside the other dependencies. - Confirm the package version in
composer.json("laravel-auto/migrations": "^1.0.4"), and ensurelaravel-auto/migrationsis registered via auto-discovery. - Copy
.env.exampleto.env, configure MySQL credentials, and runphp artisan key:generatebefore running migrations; themigrate:autocommand expects a database connection.
Usage in this repo
- Define each model’s schema in a static
migration(Blueprint $table)method. For example, create tables, timestamps, and unique indexes directly inside the model class instead of writing a separate migration file. - Add an optional
public $migrationOrderproperty when a table must be created before another (pivot tables, child models, etc.). Models without the property default to order0. - When you need a model and factory that already include the migration scaffolding, run
php artisan make:amodel MyModel(use--forceto replace existing files,--no-static-migrationto skip the auto migration stub, or--no-soft-delete/--no-factoryto adjust generated artifacts). - Run
php artisan migrate:autoafter you’ve updated or added models to let the package compare the declared schema to the database. Use-f/--freshto drop all tables first,-sto seed afterward, and--forcewhen running in production.
Example model definition
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Eloquent\Model;
class Invoice extends Model
{
public static function migration(Blueprint $table): void
{
$table->id();
$table->foreignId('customer_id')->constrained()->cascadeOnDelete();
$table->decimal('total_amount', 15, 2);
$table->enum('status', ['draft','paid','cancelled'])->default('draft');
$table->timestamps(3);
}
}
Run the command after editing models:
php artisan migrate
php artisan migrate:auto
Workflow tips
- Treat
migrate:autoas a follow-up to the regular migration run: the normal migration files indatabase/migrations/execute first, then the model-based schemas run. - If you ever need to customize the stub used by
php artisan make:amodel, publish the package stubs withphp artisan vendor:publish --tag=laravel-automatic-migrationsand updateconfig/auto-migrate.phpto pointstub_pathatresources/stubs/vendor/laravel-automatic-migrations. - Keep schema changes in the models synchronized with the project’s
laravel-autosettings so the command can safely diff the schema.
References
- Package README
composer.json(laravel-auto/migrationsentry)
スコア
総合スコア
リポジトリの品質指標に基づく評価
SKILL.mdファイルが含まれている
ライセンスが設定されている
100文字以上の説明がある
GitHub Stars 100以上
3ヶ月以内に更新がある
10回以上フォークされている
オープンIssueが50未満
プログラミング言語が設定されている
1つ以上のタグが設定されている
レビュー
レビュー機能は近日公開予定です