How to create new empty database with Laravel over Model

前端 未结 5 1559
清酒与你
清酒与你 2021-01-25 20:55

is there any way to create new database with Laravel CodeBehind ? I mean, I\'m not able to use php artisan or something like that. Just because I want

5条回答
  •  失恋的感觉
    2021-01-25 21:02

    You can create as many Databases from controller by passing the dbname like this

    public function index() {
        $userName = 'bigboytr';  // Your Database name to be created
        DB::statement("CREATE DATABASE $userName");
    }
    

    Warning :

    You don't need to create one database for every user as it will make the system very complex. Ex., If you have some thousands of user in some case, then moving the user's information to registered users 'general' database would be very tough

    Recommendation :

    What i suggest you it to create a new table for unregistered user, so that you can move them to registered user's table, which would make your process easy.

    Tip :

    You can compare the Database Engine and choose the best for your match like this

提交回复
热议问题