Search
 
SCRIPT & CODE EXAMPLE
 

PHP

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

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 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 :: PHP Fatal error: Allowed memory size of 134217728 bytes exhausted 
Php :: laravel check if item is in collection 
Php :: php submit form in new tab 
Php :: Best debugging tools for php 
Php :: using where like in laravel 8 
Php :: laravel multiple paginate 
Php :: drupal 9 modify a views query 
Php :: laravel pagination with query string, laravel pagination with string 
Php :: hoew to store a cookie php 
Php :: php variable in echo 
Php :: DateTime and Timestamps 
Php :: laravel controller create command in a folder 
Php :: laravel seeding with relationships 
Php :: php random 
Php :: install php version 7.3 ubuntu 
Php :: php remove first word from string 
Php :: adminlte in laravel 8 
Php :: ver version de php en linux 
Php :: check if variable is set and not empty laravel 
Php :: how to print string plus variable in php 
Php :: The `php` command cannot be found. Please verify that PHP is installed, or set the `php.executables` setting. 
Php :: laravel route param blade 
Php :: php ip log 
Php :: php check if all array values are the same 
Php :: laravel read csv file 
Php :: removing index.php in codeigniter 
Php :: multiple submit button in php 
Php :: php check if parameter exists in url 
Php :: laravel latest from relationship 
Php :: custom autoload without composer php psr4 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =