How to create a table via Artisan in laravel?

Create a table in database via Artisan in laravel

Step1: First you need to go on your root directory

Step2: php artisan migrate:make create_users_table
paste this code into your command interface

Step3: Check the file named 2014_mm_dd_114554_create_users_table.php in your Root\app\database\migrations folder

Step4: There will be two method Up and Down
paste this Schema in this method

 public function up()
    {
        //
        Schema::create('users', function($table)
        {
            $table->increments('id');
            $table->string('email')->unique();
            $table->string('name');
            $table->timestamps();
        });
    }

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

Step5: Run this command on your root directory
php artisan migrate





You  can check the database there will a users table having fields id,email,name etc


Comments