create foreign key snippet Laravel

In this code snippet, we generated a foreign key constraint with the users table. Foreign keys were defined in this way in earlier versions of Laravel.
 avatar
decayingMind
php
2 years ago
137 B
4
Indexable
<?php

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