laravel foreign key
snippet in php

laravel foreign key

user654

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();
});

laravel migration foreign key 5.6

user2409

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

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

migrate to an existing table in laravel commad

user5449

php artisan make:migration add_paid_to_users_table --table=users

laravel drop foreign column

user4569

// Searched, laravel drop foreign column
Schema::table('users', function (Blueprint $table) {
    $table->dropColumn(['votes', 'avatar', 'location']);
});

laravel migration integer

user1008

$table->bigInteger('votes');

foreign key string laravel

user5792

Schema::table('portfolios', function (Blueprint $table) {
            $table->string('filter_alias');
            $table->foreign('filter_alias')->cascadeOnDelete()->references('alias')->on('filters');
        });