How to create a database automatically in Laravel with all tables?

Asked

Viewed 1,200 times

5

Well I need help in a problem, I am developing a system for the first time in Latin and I need to create a database for each user registered in my system, these databases should have the same tables I’ve discovered with switching the query for each base but do not know how to create a new base already with all tables automatically, I already have the base with the users and on this basis I will store which database of each user in this user base, I am using sqlite currently during development. Please someone help me or explain to me if I have to do otherwise. And if possible would like to know how to execute migrate on all basis or at several at once.

  • 1

    I think you can start by getting what you want: https://www.youtube.com/watch?v=EDNYywKZ6jc

  • perfect this guy video helped a lot

  • Sounds like a pretty unusual requirement, make sure you’re not going through the "xy problem"

1 answer

0

I hope to help:
All Laravel documentation is here: https://laravel.com/docs/5.8/installation To create Migration, use the following command:

php artisan make:migration create_nomedatabela_table

When creating Migration, you will notice that the up() and down() functions will be created. In the up() function, you will place the table fields. Below a small example:

public function up()
    {
        Schema::create('flights', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->string('airline');
            $table->timestamps();
        });
    }

After all Migrations created, to run them use:

php artisan migrate

The documentation for Migrations is here: https://laravel.com/docs/5.8/migrations



==============================================================================

An interesting way for you to perform Migration automatically is by using this Xethron/Migrations-Generator

To install the package use the command:

composer require --dev "xethron/migrations-generator"

Then paste these lines of code into the file config/app.php:

Way\Generators\GeneratorsServiceProvider::class,
Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider::class,

How to use:

You create your tables in your database, as you are used to, and then execute the commands;

a) to create ALL tables in the database:

php artisan help migrate:generate

b) To create specific tables:

php artisan migrate:generate table1,table2,table3,table4,table5

I hope I’ve helped.

Hug

Browser other questions tagged

You are not signed in. Login or sign up in order to post.