Creating database table in laravel using migration

19. April 2016 Beginner, Laravel 1
Creating database table in laravel using migration

In the previous post,  we saw how to set up a database in laravel. Now here we ‘ll create database table.

First create a database, here am using phpmydamin in localhost to create a new database named justLaravel,

justLaravel - Creating a database
justLaravel – Creating a database


edit the settings in .env file or/and database.php file as said in previous post, setting up databse in laravel

open .env file (located at ./env)

Double the learning and saving. Buy 1 Get 1 on premium e-degrees

here am not using a password for my phpmyadmin, so i left it blank.

If you want to edit in database.php file(located at /config/database.php)

Now after the database is setup, we ll create a table using artisan make command,  when we run php artisan make:migration tablename, it will create a new migration (/database/migrations/tablename.php)

justLaravel - Creating table
justLaravel – Creating table

When opened that file, it looks like,

We write our schema for creating a table in function up( ), function down( ) is used to reverse the migrations, drop the table.

In funtion up( ), we ‘ll create a table named people with primary  key ‘id’, first and last name, unique email,  remember token, and timestamps.

Now we ‘ll run php artisan migrate

justLaravel - Tables Migration
justLaravel – Tables Migration


Now if we open phpmyadmin and we can see, the table people we just created,

justLaravel - Table Created
justLaravel – Table Created

We successfully created a table, for reference look at the previous post on setting up database.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.