// This works
php artisan make:migration create_transactions_table
// But this works too
php artisan make:migration "create transactions table"
Schema::table('users', function (Blueprint $table) {
$table->string('phone')->after('email');
});
Schema::table('users', function (Blueprint $table) {
$table->string('phone')->before('created_at');
});
Schema::table('users', function (Blueprint $table) {
$table->string('uuid')->first();
});
class ChangeFieldsProductsTable extends Migration
{
public function up()
{
//
}
}
class ChangeFieldsProductsTable extends Migration
{
public function up()
{
Schema::table('products', function (Blueprint $table) {
//
})
};
}
class WhateverYouWant extends Migration
{
public function up()
{
Schema::table('products', function (Blueprint $table) {
//
})
};
}
// Artisan command
php artisan migrate --pretend
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(
{
Schema::table('people', function (Blueprint $table) {
$table->string('first_name')->nullable();
});
}
public function down()
{
Schema::table('people', function (Blueprint $table) {
$table->dropColumn('first_name');
});
}
};
$table->unsignedInteger('interval')
->index()
->comment('This column is used for indexing.')
if (Schema::hasTable('users')) {
// The "users" table exists...
}
if (Schema::hasColumn('users', 'email')) {
// The "users" table exists and has an "email" column...
}
Schema::table('uers', function (Blueprint $table) {
$table->after('password', function ($table) {
$table->string('address_line1');
$table->string('address_line2');
$table->string('city');
});
});