laravel migration schema code example
Example 1: laravel foreign key
Schema::table('posts', function (Blueprint $table) {
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');
});
OR
Schema::table('posts', function (Blueprint $table) {
$table->foreignId('user_id')->constrained();
});
Example 2: migration rollback
php artisan migrate:rollback
Example 3: artisan refresh
Try this command it works for me
php artisan migrate:fresh
However, be careful! This command will drop all data from your DB:
Example 4: how to make-migrations in laravel
php artisan make:migration create_users_table --create=users
php artisan make:migration add_votes_to_users_table --table=users
Example 5: create migration laravel
php artisan make:Model Product -m -c --resource