Search
 
SCRIPT & CODE EXAMPLE
 

PHP

add another column in a table in laravel

<?php

use IlluminateSupportFacadesSchema;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;

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');
        });
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: radio button select in php 
Php :: laravel storage link without command line 
Php :: class php 
Php :: codeigniter 3 or where in 
Php :: mysqli exception handling 
Php :: laravel trans with parameters 
Php :: php validate colour 
Php :: laravel validate form data unique 
Php :: read xml file in php wordpress 
Php :: How to add custom button in wordpress admin section 
Php :: function inside model laravel 
Php :: mysql extension php enable 
Php :: job with queue name 
Php :: create a laravel project 
Php :: get file request in laravel 
Php :: laravel validation string type 
Php :: symfony connect rabbitMQ 
Php :: update checkbox value in laravel 
Php :: laravel model uploaded file name 
Php :: script inside php 
Php :: function default value 
Php :: laravel 6 make http request 
Php :: php hour between 
Php :: Remove .php extension & Remove trailing slash 
Php :: laravel has many with ids 
Php :: how to use attempt in laravel 
Php :: php object is empty 
Php :: laravel create many to many table 
Php :: resource route laravel 8 
Php :: how to get array key in php 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =