diff --git a/app/Models/V1/Book.php b/app/Models/V1/Book.php index 7857beb..367fbb9 100644 --- a/app/Models/V1/Book.php +++ b/app/Models/V1/Book.php @@ -8,7 +8,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; -use Illuminate\Database\Eloquent\Relations\HasManyThrough; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; class Book extends Model { @@ -66,10 +66,10 @@ public function reviews(): HasMany } /** - * Get all of the categories for the book. + * The categories that belong to the book. */ - public function categories(): HasManyThrough + public function categories(): BelongsToMany { - return $this->hasManyThrough(Category::class, BookCategory::class); + return $this->belongsToMany(Category::class, "book_categories"); } } diff --git a/app/Models/V1/Category.php b/app/Models/V1/Category.php index 4fa421c..288a22a 100644 --- a/app/Models/V1/Category.php +++ b/app/Models/V1/Category.php @@ -4,7 +4,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\HasManyThrough; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; class Category extends Model { @@ -20,10 +20,10 @@ class Category extends Model ]; /** - * Get all of the books for the category. + * The books that belong to the category. */ - public function books(): HasManyThrough + public function books(): BelongsToMany { - return $this->hasManyThrough(Book::class, BookCategory::class); + return $this->belongsToMany(Book::class, "book_categories"); } }