MOTOSHARE 🚗🏍️

Rent Bikes & Cars Directly from Owners

Motoshare connects vehicle owners with people who need bikes and cars on rent. Owners earn from idle vehicles, and renters get flexible ride options.

Visit Motoshare

Creating tables in Migration

Laravel

In Laravel to create a new database table first of all we need to make a migration which we have explained in the previous blog. I recommend you to read that blog, you can refer the link given below:


https://www.scmgalaxy.com/tutorials/explanation-of-database-migrations-in-laravel-5-8/

Once we are done with creating a migration file, to create a new database
table we have to use the create method on the Schema facade. The create method accepts two arguments:-

The first is the name of the table, while the second is a closure which receives a Blueprint object that may be used to define the new table:

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

Schema::create('users', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->string('email');
    $table->timestamps();
});

In the table we can add number of $table as per our requirement. There are several data type which we can use while creating the $table. Few of them are given below:

bigIncrements()

The bigIncrements method creates an auto-incrementing UNSIGNED BIGINT (primary key) equivalent column:

$table->bigIncrements('id');

bigInteger()

The bigInteger method creates a BIGINT equivalent column:

$table->bigInteger('votes');

id()

The id method is an alias of the bigIncrements method. By default, the method will create an id column; however, you may pass a column name if you would like to assign a different name to the column:

$table->id();

rememberToken()

The rememberToken method creates a nullable, VARCHAR(100) equivalent column that is intended to store the current “remember me” authentication token:

$table->rememberToken();

string()

The string method creates a VARCHAR equivalent column of the given length:

$table->string('name', 100);

text()

The text method creates a TEXT equivalent column:

$table->text('description');

To know more about creating tables and adding columns, you can refer the video given below:

Joydeep M
Latest posts by Joydeep M (see all)
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x