Answers for "how to get name based on id foreign key laravel"

PHP
0

foreignId in laravel

// for laravel 7 or above. 
$table->foreignId('user_id')->constrained();
/*-----------OR---------------*/
$table->foreignId('user_id')->constrained('users');
Posted by: Guest on January-04-2022
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 "how to get name based on id foreign key laravel"

Browse Popular Code Answers by Language