In Laravel we can change our configuration in the. env file of the project root directory.
After opening the. env file, find the DB prefix for several fields to change our configuration, if you want to do more configuration can be modified in \config\database.php.
Once configured, let's initialize the database and use Laravel's own migration to generate the user and password tables:
PHP Artisan Migrate
After executing this command, you will find that the database has more user and password tables so that our database is configured.
Database Migration--
Migrations
Migration is a database migration, can also be called as version control, so that others download your source code with these migration files only need to execute PHP artisan migrate command to generate all the tables, it is convenient.
Create a migration file
The name of the migration file we created should be clear, and later--create=articles declares a articles table to be created.
In \database\migrations\ we can see the migration file we just created:
classCreatearticlestableextendsmigration{/** * Run the migrations. * * @return void*/ Public functionUp () {Schema:: Create (' articles ',function(Blueprint$table) { $table->increments (' id '); $table-timestamps (); }); } /** * Reverse the migrations. * * @return void*/ Public functionDown () {Schema::d rop (' articles '); }}
There are two methods: up and down,up nothing to say, is the field to be loaded when executing the migrate command, down is what to do when the rollback.
Execute command:
PHP Artisan Migrate
After opening the table ... Oh.. Forgot to add the field, at this point we can create such a migration:
PHP Artisan make:migration insert_content_to_articles--table=articles
The--table=articles at this point is that we are going to make some changes to the articles table and edit this migration:
<?PHP UseIlluminate\database\schema\blueprint; Useilluminate\database\migrations\migration;classInsertcontenttoarticlesextendsmigration{/** * Run the migrations. * * @return void*/ Public functionUp () {Schema:: Table (' articles ',function(Blueprint$table) { //Add the fields we want $table-string(' content '); }); } /** * Reverse the migrations. * * @return void*/ Public functionDown () {Schema:: Table (' articles ',function(Blueprint$table) { //the corresponding rollback operation $table->dropcolumn (' content '); }); }}
Perform a migrate operation to see if the operation was successful.
Rollback operation
Roll back the Last migration:
PHP Artisan Migrate:rollback
Roll back all the migrations:
PHP Artisan Migrate:reset
Laravel5.1 Configuration database and migration