Challenge 1: Add a belongsTo/hasMany Pair — Possible Solution ==================================================================== # php artisan make:model Publisher -m // database/migrations/..._create_publishers_table.php public function up(): void { Schema::create('publishers', function (Blueprint $table) { $table->id(); $table->string('name'); $table->timestamps(); }); } public function down(): void { Schema::dropIfExists('publishers'); } // Migration to add publisher_id to the existing books table Schema::table('books', function (Blueprint $table) { $table->foreignId('publisher_id')->constrained()->onDelete('cascade'); }); // app/Models/Publisher.php namespace App\Models; use Illuminate\Database\Eloquent\Model; class Publisher extends Model { protected $fillable = ['name']; public function books() { return $this->hasMany(Book::class); } } // app/Models/Book.php — add the inverse relationship protected $fillable = ['title', 'price', 'author_id', 'publisher_id']; public function publisher() { return $this->belongsTo(Publisher::class); } # Usage $publisher = Publisher::find(1); $publisher->books; // every book from this publisher $book = Book::find(1); $book->publisher->name; // this book's publisher WHY THIS WORKS -------------- - $table->foreignId('publisher_id')->constrained()->onDelete('cascade') is Eloquent's fluent shorthand for adding a foreign key column — it infers the referenced table (publishers) and column (id) from the column name publisher_id by convention, and sets up an actual database foreign key constraint with CASCADE delete behavior, all in one line. - Publisher::hasMany(Book::class) and Book::belongsTo(Publisher::class) are two SEPARATE method declarations, one per model — unlike Django's single ForeignKey field declaration that implicitly creates both directions, Eloquent requires writing out each side of the relationship explicitly on its own model. - publisher_id was added to Book's $fillable array — without this, mass assignment (e.g. Book::create([...])) couldn't set which publisher a new book belongs to, even though the relationship method itself would still work for already-created records.