Adding Columns to a Table Without Laravel Losing Data
As our projects develop over time, the existing table structure may become insufficient. For this, our table needs a new column.
In this article, I will show you how to add a new column
to our current table without losing data.
If you run the code below in our controller file
, it will add a new column to our existing table.
Schema::table('tableName', function (Blueprint $table){
if(!Schema::hasColumn('tableName', 'newColumnName')){
$table->string('newColumnName')->after('id');
}
});
Comments
Popular Articles
Popular Tags
- #directive
- #Function
- #Json
- #Class
- #SASS
- #Form
- #Redirect
- #API
- #Special Characters
- #Special
- #Random
- #Generating
- #
- #Text
- #Ajax
- #URL
- #Encrypting
- #React
- #Show
- #timeAgo
- #PSR-4
- #Hide
- #DDOS Protection
- #DDOS
- #cURL
- #Logic For Displaying Posts
- #Error
- #Key
- #General Error
- #1364 Field
- #Abbreviation
- #Blade
- #Version
- #QR
- #QR Code Generating
- #Array
- #Arrays with Key Values to String Statement
- #Short Tag
- #Activate
- #Real Time
- #Socket.io
- #301
- #Custom Directives
- #Iframe Detection
- #Date
- #Characters
- #Insert
- #Autoloader
- #Composer
- #Reading
There are no comments, make the firs comment