Daolin
Daolin

Reputation: 634

How to connected to existing MySQL database in Laravel 5?

I'm building a web application using Laravel 5. The tutorial I followed started with no data.

  1. Create migrate table.

    It uses:

    php artisan make:migration create_table-name_tables --create="table_name"
    
  2. Set up schema

    Then set up table schema in /database/migrations/_create_table-name_tables.php .

  3. Perform migration: php artisan migrate.

  4. Seeders.

    Create /database/seeds/table-nameTableSeeder.php. In this file there is actual rows in the table defined.

  5. Add seed class to /database/seeds/DatabaseSeeder.php:

    use Illuminate\Database\Seeder;
    use Illuminate\Database\Eloquent\Model;
    
    class DatabaseSeeder extends Seeder {
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Model::unguard();
    
        $this->call('Table-nameTableSeeder');       
    }
    
    }
    
  6. Seed with:

    composer dump-autoload
    php artisan db:seed
    

    My question: If I already have a existing database. How do I modify migration steps to use my database? Do I just need to do step 1,2 and 3? Then I can move on to Creating models?

Thanks in advance!

Upvotes: 3

Views: 1741

Answers (1)

Zsw
Zsw

Reputation: 4087

According to the documentations:

Laravel includes a simple method of seeding your database with test data using seed classes.

That is to say, seeding your database is for testing purposes. So yes, if you already have an existing database with data in it, there is no need to seed it any further unless you need additional data.

Upvotes: 2

Related Questions