Page MenuHomePhorge

2021_11_10_100000_add_group_name_column.php
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

2021_11_10_100000_add_group_name_column.php

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
// phpcs:ignore
class AddGroupNameColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table(
'groups',
function (Blueprint $table) {
$table->string('name')->nullable()->after('email');
}
);
// Fill the name with the local part of the email address
DB::table('groups')->update([
'name' => DB::raw("SUBSTRING_INDEX(`email`, '@', 1)")
]);
Schema::table(
'groups',
function (Blueprint $table) {
$table->string('name')->nullable(false)->change();
}
);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table(
'groups',
function (Blueprint $table) {
$table->dropColumn('name');
}
);
}
}

File Metadata

Mime Type
text/x-php
Expires
Mon, Oct 19, 11:55 PM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1516968
Default Alt Text
2021_11_10_100000_add_group_name_column.php (1 KB)

Event Timeline