#Part2 laravel 5 Blog Tutorial : Database & Migration

Create Blog Apps in Laravel 5 - make simple blog using laravel 5.3 at this lessons will teach us about working with database and crate a migration in Laravel project.

that tutorial was published on previews lessons, pleas read :
  1. How to Connect Database in laravel 5.3
  2. Database Migration & Schema in Laravel 5.3

In this lessons, i assume you must see of the part1 before follow this tutorial, read Introductions to CRUD Operations in laravel 5.3 Part 1

Create Blog using laravel 5.3

Create Database

First, we will need to create a Database (i use MySQL database) in your server. So just create your own database. you can see this tutorial how to make an MySQL database?

Create Laravel Project

with your Terminal (CMD in windows), following this "Artisan CLI" command to create new project in laravel 5.3 :

composer create-project --prefer-dist laravel/laravel web

Intructions :

  1. we will create Laravel project using Composer
  2. web is your project name

Connect with Database

Next, we will create connection with our database, hasbeen posted on How to Connect Database in laravel 5.3

in your .ENV file, modife your connection variable, and configure it with yours.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_blog
DB_USERNAME=root
DB_PASSWORD=

Database Migration

Next, we need to create tables and columns in our database, using Migration in Laravel we will create a table or a columns with very easy, read Database Migration & Schema in Laravel 5.3

laravel 5 Blog Tutorial : Database & Migration

Create migration following by this command :

php artisan make:migration create_blog_table

After success, your migration file will be strored on database\migrations\2016_09_13_113838_crate_blog_table.php

Add some function following by this source code

<?php

use Illuminate\Support\Facades\Schema;
use Illuminat\eDatabase\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CrateBlogTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('blog_post', function (Blueprint $table) {
        $table->increments('id');
        $table->string('title');
        $table->string('description');
        $table->timestamps();
      });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('blog_post');
    }
}

Next, execute our migration scheme following by this command :

php artisan migrate

Now, you have a database "laravel_blog", with table name "blog_post" and some column name like, id, title,description, and time stamp in your database.


Video tutorial #Part2 laravel 5 Blog Tutorial : Database & Migration


Next lesson, we will try to show data from database and create a model in laravel 5.3

see you next lessons ...

Recomended Tutorials

Facebook
Blogger

0 Response to "#Part2 laravel 5 Blog Tutorial : Database & Migration"

Post a Comment