Enter Into Tinker Environment
On the CLI run artisan command to enter into tinker environment
php artisan tinker
Adding Columns
Run the suggested code directly from Tinker.
Schema::table('<YOUR TABLE>', function ($table) {
    $table->string('name')->nullable()
        ->after('<DESIRED COLUMN>'); // add after desired column
});
Renaming Columns
Run the suggested code directly from Tinker.
Schema::table('<YOUR TABLE>', function ($table) {
    $table->renameColumn('<FROM>', '<TO>');
});
Removing Columns
Run the suggested code directly from Tinker.
Schema::table('<YOUR TABLE>', function ($table) {
   $table->dropColumn('<DESIRED COLUMN>');
});
You may drop multiple columns from a table by passing an array of column names to the dropColumn method:
Schema::table('<YOUR TABLE>', function ($table) {
   $table->dropColumn(['<DESIRED COLUMN>', '<DESIRED COLUMN 1>']);
});
Note
You can also use arrow functions
Schema::table('<YOUR TABLE>', fn($t)=> $t->string('<DESIRED COLUMN>')->nullable());
 

 
    
Top comments (0)