Laravel : create a table file and generated table in database using migration

In this tutorial learn how to create/generate table in database  using php artisan migrate function in laravel, How to create a table into database using php artisan make:migration, let's go step by step.

To create a migration, use the make:migration

1. Create Table
php artisan make:migration create_users_table = users

2.  Migration structure in project_name/database/migration/2019_10_12_000000_create_users_table.php
   
  Within both of these methods you may use the Laravel schema builder to expressively create and modify tables. To learn about all of the methods available on the Schema builder

<?php

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

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

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


 3. Running Migrations for creating a tables into the database, make sure, database connection details added in .env

To run all migrations, execute the migrate Artisan command:

php artisan migrate
OR  use force if not work just migration
php artisan migrate --force

1 comment:

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...