Laravel: Run migrations on another database

前端 未结 8 2078
有刺的猬
有刺的猬 2020-12-29 23:15

In my app every user has its own database that created when user registered. Connection and database data (database name, username, password) are saved in a table in default

8条回答
  •  孤独总比滥情好
    2020-12-29 23:38

    I have the same problem, my solution is to change the database using Config::set first then run Artisan::call("migrate"). so based on your code:

    DB::statement(DB::raw('CREATE DATABASE ' . $database_name));
    Config::set('database.connections.mysql.database', $database_name);
    Artisan::call("migrate --database=mysql");
    

    the config only changed on your session then reset later as your current setting.

提交回复
热议问题