laravel change column type migration code example
Example 1: laravel migration change column name
Schema::table('users', function (Blueprint $table) {
$table->renameColumn('from', 'to');
});
Example 2: laravel rollback last migration
php artisan migrate:rollback --step=1
Example 3: 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 4: laravel migration change column type
public function up()
{
Schema::table('sometable', function (Blueprint $table) {
$table->text('text')->change();
});
}