Answers for "laravel 8 connect tables with foreign key"

PHP
5

foreign key in laravel migration

$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
Posted by: Guest on June-21-2021
1

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();
    });
}
Posted by: Guest on September-27-2021

Code answers related to "laravel 8 connect tables with foreign key"

Browse Popular Code Answers by Language