Search
 
SCRIPT & CODE EXAMPLE
 

PHP

make a forign key in migrations using laravel 8

$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
Comment

laravel foreign key

Schema::table('posts', function (Blueprint $table) {
    $table->unsignedBigInteger('user_id');

    $table->foreign('user_id')->references('id')->on('users');
});
OR
Schema::table('posts', function (Blueprint $table) {
    $table->foreignId('user_id')->constrained();
});
Comment

foreign key in Laravel

// one_line code for foreign in laravel
$table->foreignId('user_id')->constrained()->onDelete('cascade');
Comment

add foreign key column laravel 5.8

update your `integer('user_id')` to `bigInteger('user_id')`
public function up() { 
        Schema::create('evaluation', function (Blueprint $table) { 
            $table->increments('id'); 
            $table->bigInteger('user_id')->unsigned()->index(); 
            $table->timestamps();
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        });
    }
Comment

laravel foreign key constraint

public function up()
{
    Schema::create('replies', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->text('body');
        $table->unsignedBigInteger('question_id');
        $table->integer('user_id')->unsigned();
        $table->foreign('question_id')->references('id')->on('questions')->onDelete('cascade');
        $table->timestamps();
    });
}
Comment

create foreign key laravel migration

Schema::table('posts', function (Blueprint $table) {
    $table->unsignedBigInteger('user_id');

    $table->foreign('user_id')->references('id')->on('users');
});
Comment

laravel 8 foreign key migration

use IlluminateDatabaseSchemaBlueprint;
use IlluminateSupportFacadesSchema;

Schema::table('posts', function (Blueprint $table) {
    $table->unsignedBigInteger('user_id');

    $table->foreign('user_id')->references('id')->on('users');
});
Comment

laravel foreign key

//acording to laravel 7>=

Schema::table('posts', function (Blueprint $table) {
    $table->foreignId('user_id')->constrained();
});

//for deffirent table
$table->foreignId('user_id')->constrained('users');

//for taking action
$table->foreignId('user_id')
      ->constrained()
      ->onUpdate('cascade')
      ->onDelete('cascade');
Comment

laravel change foreign key name

//Note : Before Renaming Foreign, You Must Need To Delete Old Foreign And Assign New One
class RenameColumn extends Migration
{

    public function up()
    {
        Schema::table('holidays', function(Blueprint $table) {
            $table->dropForeign('holidays_account_id_foreign');
            $table->renameColumn('account_id ', 'engagement_id');

            $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
        });
    }

    public function down()
    {
        Schema::table('holidays', function(Blueprint $table) {
            $table->dropForeign('holidays_engagement_id_foreign');
            $table->renameColumn('account_id ', 'engagement_id');

            $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
        });
    }
}
Comment

foreign key laravel migration

$table->foreign('column_name')->references('id')->on('table_name')->onDelete('cascade');
Comment

add foreign key in laravel migration

$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
Comment

laravel 8 foreign key

Schema::table('posts', function (Blueprint $table) {
    $table->foreignId('user_id')->constrained();
});
Comment

Laravel adding Foreign Key Constraints

$table->foreignId('user_id')
      ->constrained("users") <- // You don't need to specify table if it matched laravel naming conventions.
      ->onUpdate('cascade')
      ->onDelete('cascade');
Comment

laravel foreign key

$table->foreignId('user_id')
      ->constrained()
      ->onUpdate('cascade')
      ->onDelete('cascade');
Comment

Laravel create foreign key column in migration

$table->foreignId('post_id')
                ->constrained()
                ->onUpdate('cascade')
                ->onDelete('cascade');
Comment

laravel foreign

$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')
Comment

Laravel migrations custom foreign key

$table->unsignedBigInteger('created_by');
$table->foreign('created_by')->references('id')->on('users');
Comment

How to create foreign key in Laravel

$table->foreign('category_id')->references('id')->on('categories')->onUpdate('cascade')->onDelete('cascade');
Comment

PREVIOUS NEXT
Code Example
Php :: laravel auth user in constructor 
Php :: installing bootstrap on laravel8 
Php :: laravel auth login with phone or email 
Php :: store emoji in php 
Php :: offset codeigniter 3 
Php :: livewire not working 
Php :: fnmatch php ignore case 
Php :: php remove and  
Php :: javascript date to php date 
Php :: Fetch Data From Database With PDO 
Php :: eloquent pluck multiple columns 
Php :: Server Requirements in laraavel 9 
Php :: wpdb num_rows 
Php :: insert data using mysqli in php 
Php :: how to get plugin directory path in wordpress 
Php :: remove product from cart by id woocommerce 
Php :: how do i open a new tab with php 
Php :: convert to json php 
Php :: Remove public from the url in the codeigniter 
Php :: What does "as" keyword mean in Laravel route ? 
Php :: composer update php mbstring.so missing 
Php :: laravel observer events 
Php :: register sidebar wordpress 
Php :: php add to existing associative array 
Php :: php extract last n words of string 
Php :: laravel httaccess for apache 
Php :: wp get_posts return ids 
Php :: convert time to 24 hour format laravel 
Php :: fresh migrqte laravel 
Php :: phone number validation, laravel 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =