Laravel Foreign relationships
Within Laravel there are many different ways to implement foreign keys. The way you choose to implement them doesn't matter, but it's important to be consistent.
So choose the one that works best for you and stick with it.
<?php
public function up(): void
{
Schema::create("books", function (Blueprint $table) {
$table->foreignId("author_id");
$table->foreign("author_id")
->references("id")
->on("authors");
});
}
php
<?php
public function up(): void
{
Schema::create("books", function (Blueprint $table) {
$table->unsignedBigInteger("author_id");
$table->foreign("author_id")->references("id")->on("authors");
});
}
php
<?php
public function up(): void
{
Schema::create("books", function (Blueprint $table) {
$table->foreignIdFor(\App\Models\Author::class);
});
}
php