How to run migrations on another database in laravel

0 votes

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 database.

try{
    DB::transaction(function() {

        $website = new Website();
        $website->user_id = Auth::get()->id;
        $website->save();

        $database_name = 'website_'.$website->id;

        DB::statement(DB::raw('CREATE DATABASE ' . $database_name));

        $websiteDatabase = new WebsiteDatabase();
        $websiteDatabase->website_id = $website->id;
        $websiteDatabase->database_name = $database_name;
        $websiteDatabase->save();

    });
} catch(\Exception $e) {
    echo $e->getMessage();
}

Now I want to run some migrations on new user's database after its creation.

Is it possible?

thanks

Sep 28, 2020 in Laravel by kartik
• 37,520 points
2,750 views

1 answer to this question.

0 votes

Hello @kartik,

If you place database config on the database.php file, this can help you:

php artisan migrate --database=**otherDatabase**

Hope it helps!!

Thank you!!

answered Sep 28, 2020 by Niroj
• 82,840 points

Related Questions In Laravel

0 votes
1 answer

How to get all pending jobs in laravel queue on redis?

Hello @kartik, Here is the way I do ...READ MORE

answered Apr 6, 2020 in Laravel by Niroj
• 82,840 points
9,612 views
0 votes
1 answer

How to populating a database in a Laravel migration file?

Hello @kartik, Don't put the DB::insert() inside of ...READ MORE

answered Aug 4, 2020 in Laravel by Niroj
• 82,840 points
3,110 views
0 votes
1 answer

How to run specific migration in laravel?

Hello @kartik, Use this command: php artisan migrate --path=/database/migrations/my_migration.php  And ...READ MORE

answered Aug 10, 2020 in Laravel by Niroj
• 82,840 points
4,027 views
0 votes
1 answer

How to get the id when you're validating in the model Validation unique on update using laravel?

Hello @kartik, in Laravel's inbuilt auth system, the ...READ MORE

answered Sep 11, 2020 in Laravel by Niroj
• 82,840 points
6,713 views
0 votes
1 answer

Uncaught Error: Bootstrap's JavaScript requires jQuery

Hello @kartik, You have provided wrong order for ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,840 points
23,295 views
0 votes
1 answer

How to make Bootstrap popover Appear/Disappear on hover instead of click?

Hello @kartik, Set the trigger option of the popover to hover instead ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,840 points
3,313 views
0 votes
1 answer

How to enable Bootstrap tooltip on disabled button?

Hii @kartik, You can wrap the disabled button ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,840 points
5,102 views
+1 vote
2 answers

How to set cache false for getJSON in jQuery?

You can't pass any configuration parameters to ...READ MORE

answered Oct 7, 2020 in JQuery by Amit
• 140 points
2,931 views
0 votes
1 answer

How to run some migrations on new user's database after its creation?

Hello, If you place database config on the database.php file, ...READ MORE

answered Nov 12, 2020 in Laravel by Niroj
• 82,840 points
600 views
0 votes
1 answer

What is database migration and how to create database migration in Laravel?

Hii, Migrations are like version control for your database, ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,339 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP