Migrations in laravel
This tutorial we will learn one of the features in laravel named migrations, migrations will make automatically when we want to create a table. the advantages of migrations for example there are some people who work on the same project, they do not need to export and import databases or create manual database, so when they want to take laravel project, they just run the class or method of migrations through command line or terminal, and automatically in its database will make what we want.
What is migrations ?
Migrations is one of the interesting features in laravel, with this feature when we work with teams for a project. we do not need to import or export the database or make it manually, we just need to run the command line, and automatically will be imported. and its advantages again with migrations, migrations like version control of our database. because we can undo what we have done.
Create schema migrations
Open command prompt in your laravel project. and then type this one
php artisan make:migration table_category --create=categories

php artisan make:migration : This is the laravel's command to make the migration.
table_category : This is the class name that will be created in migrations.
--create=categories : This is the name table that will be created in the database

2017_12_31_132818_table_category.php
If there is no problem then migrations class successfully created. Automatically laravel will create a class, in the class there are 2 functions, up () and down ().
up () : functions to create a database schema.
down () :function to delete the table in this tutorial table name is "categories".
class TableCategory extends Migration{ } : This is a function name that automatically becomes camelcase .
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class TableCategory extends Migration
{
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('desc');
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('categories');
}
}
Laravel will create 2 columns automatically , id and timestamp. I will add some columns in schema database like this.
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('desc');
$table->timestamps();
});
}
I added two columns . $table->string('name') ; and $table->string('desc') ; . now we do my migration in our database
Create migrations
We have created a migration schema. and add two columns, now we have to make the migration. Open the command prompt.
php artisan migrate

We have run the migration command, we can see the results in our mysql. di tutorial ini saya telah membuat databas dengan nama Test.

We can see the table category has been created automatically, and then we can see the structure of table category .

We have successfully migrated, a feature that is very useful for us if working with a team, we do not have to bother to share the database with others. so many of me hopefully this tutorial useful for you, thank you
Posted on Utopian.io - Rewarding Open Source Contributors

Congratulations @alfarisi94! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOPThank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Hey @alfarisi94 I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x