Created
October 28, 2021 07:06
-
-
Save ig0r74/a043e275009d9d846e864d3dc8ff7e50 to your computer and use it in GitHub Desktop.
Laravel migration additional changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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