Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Update relationships for book_categories table
Browse files Browse the repository at this point in the history
  • Loading branch information
kkamara committed Oct 16, 2024
1 parent b8c5d2b commit c8aae52
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions app/Models/V1/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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");
}
}
8 changes: 4 additions & 4 deletions app/Models/V1/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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");
}
}

0 comments on commit c8aae52

Please sign in to comment.