dimanche 27 septembre 2015

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!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1FBTpUe
via IFTTT

Aucun commentaire:

Enregistrer un commentaire