Add Another Column In A Table In Laravel

[Solved] Add Another Column In A Table In Laravel | Php Frameworks Laravel - Code Explorer | yomemimo.com
Question : add another column in a table in laravel

Answered by : usama-ayub

<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddStoreIdToUsersTable extends Migration
{ /** * Run the migrations. * * @return void */ public function up() { Schema::table('users', function (Blueprint $table) { // 1. Create new column // You probably want to make the new column nullable $table->integer('store_id')->unsigned()->nullable()->after('password'); // 2. Create foreign key constraints $table->foreign('store_id')->references('id')->on('stores')->onDelete('SET NULL'); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::table('users', function (Blueprint $table) { // 1. Drop foreign key constraints $table->dropForeign(['store_id']); // 2. Drop the column $table->dropColumn('store_id'); }); }
}

Source : https://stackoverflow.com/questions/16791613/add-a-new-column-to-existing-table-in-a-migration | Last Update : Mon, 12 Jul 21

Answers related to add another column in a table in laravel

Code Explorer Popular Question For Php Frameworks Laravel