Skip to content

Instantly share code, notes, and snippets.

@ig0r74
Created October 28, 2021 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ig0r74/a043e275009d9d846e864d3dc8ff7e50 to your computer and use it in GitHub Desktop.
Save ig0r74/a043e275009d9d846e864d3dc8ff7e50 to your computer and use it in GitHub Desktop.
Laravel migration additional changes
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddRoleIdToUsersTable extends Migration
{
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->foreignId('role_id')->default('1')->constrained()->after('password');
});
Artisan::call('db:seed', [
'--class' => 'RolesSeeder',
'--force' => true
]);
\App\Models\User::where('is_admin', true)
->update(['role_id' => 3]);
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('is_admin');
});
}
public function down()
{
Schema::table('users', function (Blueprint $table) {
//
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment