AddGroupOrdering::up PHP Method

up() public method

Run the migrations.
public up ( )
    public function up()
    {
        Schema::table('groups', function (Blueprint $table) {
            $table->unsignedInteger('order')->default(0);
        });
        $groups = Group::where('id', '<>', 1)->orderBy('name')->get();
        $i = 0;
        foreach ($groups as $group) {
            $group->order = $i;
            $group->save();
            $i++;
        }
    }
AddGroupOrdering