File "MigrateSchoolRollbackTable.php"

Full Path: /home/trinadezambia/public_html/admin_panel/app/Console/Commands/MigrateSchoolRollbackTable.php
File size: 1.12 KB
MIME-type: text/x-php
Charset: utf-8

<?php

namespace App\Console\Commands;

use App\Models\School;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;

class MigrateSchoolRollbackTable extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'migrate:school:rollback';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        //
        $schools = School::withTrashed()->get();

        foreach ($schools as $key => $school) {
            Config::set('database.connections.school.database', $school->database_name);
            DB::purge('school');
            DB::connection('school')->reconnect();
            DB::setDefaultConnection('school');

            Artisan::call('migrate:rollback', [
                '--database' => 'school',
                '--path' => 'database/migrations/schools'
            ]);

        }
    }
}