Laravel 13 cheatsheet
Laravel 13: Models and database
8 common Laravel 13 tasks.
Create a model and migration
Generate a model and its migration together.
php artisan make:model Post -m
Create a migration
Generate a migration file for a new posts table, then define its columns in the generated file.
php artisan make:migration create_posts_table
Run migrations
Apply outstanding migrations to the configured database.
php artisan migrate
Caution: Check your database connection and migration changes before running against production.
Check migration status
Show which migrations have run and which are pending.
php artisan migrate:status
Roll back the last migration batch
Run the down method for the most recent batch of migrations.
php artisan migrate:rollback
Caution: Rollback can remove tables or columns and their data. Review the migration and back up data first.
Rebuild a development database
Drop all tables and run every migration again.
php artisan migrate:fresh
Caution: Destructive: this drops all tables and their data. Never use on a database containing data you need.
Create a factory
Generate a model factory for development and test data.
php artisan make:factory PostFactory --model=Post
Create and run a seeder
Create a seeder, add its data in run(), then execute that seeder.
php artisan make:seeder PostSeeder
php artisan db:seed --class=PostSeeder
Caution: Seeders write to the configured database. Review their contents before running them.