运行 'php artisan migrate:fresh' Laravel 代码

Running 'php artisan migrate:fresh' in Laravel code

是否可以在没有 shell 的实际 Laravel 代码中 运行 php artisan migrate:fresh?例如,在此函数中加载 table 工厂之前。

Route::get('/seed', function () {
    // php artisan migrate:fresh
    factory(App\User::class)->create();
    factory(App\Models\Campaign::class, 20)->create();
    factory(App\Models\Model::class, 200)->create();
    factory(App\Models\Trim::class, 400)->create();
    factory(App\Models\Color::class, 800)->create();
    factory(App\Models\Specification::class, 800)->create();
    factory(App\Models\Option::class, 800)->create();
    factory(App\Models\LeaseLength::class, 800)->create();
    factory(App\Models\Mileage::class, 800)->create();
    factory(App\Models\ExtraOption::class, 800)->create();

    return redirect()->back();
});

这样做的目标是在再次播种之前清理 tables。

您可以 运行 artisan 从您的控制器发出这样的命令

use Artisan;

public function artisan()
   {
       Artisan::call('migrate:fresh');
       Artisan::call('make:seeder UsersTableSeeder');
       Artisan::call('config:clear');
   }