CUSTOM MIGRATION IN LARAVEL :
Hi Guys ,
In this lesson we are going to learn how to use custom migration and some basic thing.
while we creating migration , like nullable and foreignkey reference .
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('emp_id')->nullable();
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->string('dob')->nullable();
$table->string('is_active')->nullable();
$table->boolean('confirmed');
$table->string('status')->default(0);
$table->rememberToken();
$table->timestamps();
$table->foreign('emp_id')->references('id')->on('another_table')
->onUpdate('cascade')->onDelete('cascade');
});
}
In this above migration, Nullable is a function which is used to make our database column as null value , Default function is we can give some values to that column wheather that column values are passed or not , in foreign key 'emp_id' is current table column 'id' is primary table column , cascade function is for when the primary key is deleted it will delete the reference foreign key value also.
This is some basic migration function , if you guys known something please hit a comment .
Hope this post will usefull for us :)
Hi Guys ,
In this lesson we are going to learn how to use custom migration and some basic thing.
while we creating migration , like nullable and foreignkey reference .
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('emp_id')->nullable();
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->string('dob')->nullable();
$table->string('is_active')->nullable();
$table->boolean('confirmed');
$table->string('status')->default(0);
$table->rememberToken();
$table->timestamps();
$table->foreign('emp_id')->references('id')->on('another_table')
->onUpdate('cascade')->onDelete('cascade');
});
}
In this above migration, Nullable is a function which is used to make our database column as null value , Default function is we can give some values to that column wheather that column values are passed or not , in foreign key 'emp_id' is current table column 'id' is primary table column , cascade function is for when the primary key is deleted it will delete the reference foreign key value also.
This is some basic migration function , if you guys known something please hit a comment .
Hope this post will usefull for us :)
Custom Migration In Laravel
Reviewed by AD
on
December 05, 2017
Rating:

No comments: