How to Remove Column from Table in Laravel Migration?
In this post we will give you information about How to Remove Column from Table in Laravel Migration?. Hear we will give you detail about How to Remove Column from Table in Laravel Migration?And how to use it also give you demo for it if it is necessary.
Hi Artisan,
In this quick example, let’s see laravel migration remove column. This post will give you simple example of how to drop column in laravel migration. i would like to show you remove column laravel migration. We will use drop field laravel migration.
Laravel 5 - Class 'Input' not found issue?
In this post we will give you information about Laravel 5 - Class 'Input' not found issue?. Hear we will give you detail about Laravel 5 - Class 'Input' not found issue?And how to use it also give you demo for it if it is necessary.
When i start to work on Laravel 5.2 at that time i fetch this problem "Class 'Input' not found". When i copy my old controller code from laravel 5.1 version that time i found this issue, but i also could use Input insted to Request but i want to use Input as it is. But at last found solution. you have to just use following aliase on your controller.
use IlluminateSupportFacadesInput as Input
Hope this code and post will helped you for implement Laravel 5 - Class 'Input' not found issue?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs
I will give you some example that way you can easily remove column using migration. let’s see bellow example that will help you.
1) Remove Column using Migration
2) Remove Multiple Column using Migration
3) Remove Column If Exists using Migration
1) Remove Column using Migration
<?php
use IlluminateSupportFacadesSchema;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;
class ChangePostsTableColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('posts', function (Blueprint $table) {
$table->dropColumn('body');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}
2) Remove Multiple Column using Migration
<?php
use IlluminateSupportFacadesSchema;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;
class ChangePostsTableColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('posts', function (Blueprint $table) {
$table->dropColumn(['body', 'title']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}
3) Remove Column If Exists using Migration
<?php
use IlluminateSupportFacadesSchema;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;
class ChangePostsTableColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (Schema::hasColumn('posts', 'body')){
Schema::table('posts', function (Blueprint $table) {
$table->dropColumn('body');
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}
I hope it can help you…
Hope this code and post will helped you for implement How to Remove Column from Table in Laravel Migration?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs