Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

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');
Source by laravel.com #
 
PREVIOUS NEXT
Tagged: #laravel #foreign #key
ADD COMMENT
Topic
Name
6+9 =