How to add columns in existing table using migration in laravel
How to add columns in existing table using migration in laravel
Through many examples, we will learn how to resolve the "How to add columns in existing table using migration in laravel".
-
Add new columns in existing table using migration in laravel 8
//1. Run php artisan make:migration command to create migration file. php artisan make:migration add_publish_to_comments --table=comments //2. Add columns to your migration file under - database\Migrations\<your_migration_filename>.php. public function up() { Schema::table('comments', function (Blueprint $table) { $table->boolean('is_publish')->default(0); }); } public function down() { Schema::table('comments', function (Blueprint $table) { $table->dropColumn('is_publish'); }); } //3. Migration command to create database table structure.</p> //Migrate to this file php artisan migrate --path=database\Migrations\2021_04_12_085751_add_publish_to_comments.php Or //Migrate all files php artisan migrate
You can add columns in existing table using the migration command
php artisan make:migration add_publish_to_comments --table=comments
. Use a specific migration file name which is not already exist in your migrations folder. After that add columns to the migration file and run migrate command. This is how you can add columns to your existing database table in laravel without changing the table structure manually using PhpMyAdmin MySQL Database. Change table name, migration file name as per your requirements.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0"
- How to get last year records count with month wise in Laravel
- How to get specific columns using with method in laravel Eloquent relationship
- Return view from route Laravel
- Best code example for create order in Laravel for ecommerce
- Laravel 11 project setup on localhost using breeze with blade step by step
- Symlink(): No such file or directory
- Get ids in array from users table
- Attempt to read property "avatar" on null in Laravel
- Split an Eloquent Collection by half in Laravel
- How to create and run user seeder in laravel
- Get current month records in laravel 7/8
- Route group with URI prefix using middleware and route name prefixes
- Pass value from controller to model in laravel
- How to get user information using hootlex/laravel-friendships package in laravel
- Touch parent updated_at in Laravel
- Class 'App\Http\Controllers\User' not found
- Eager loading dynamically in laravel
- Php artisan make model, factory, migration and controller in single command
- Conditional validation in laravel
- Generate random string lowercase in Laravel
- How to get database name in Laravel 9 ?
- In order to use the Auth::routes() method, please install the laravel/ui package
- Create a record if not exist in laravel
- How to call model in blade laravel