Files
opentextsummaries/app/Models/Book.php
T

75 lines
1.4 KiB
PHP
Raw Normal View History

2025-09-13 17:39:17 +03:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Book extends Model
{
protected $fillable = [
'title',
'slug',
'author',
'cover_image',
'publication_date',
'description',
'category_id',
];
2025-09-20 16:47:41 +03:00
/**
* Use slug for route model binding and URL generation.
*/
public function getRouteKeyName(): string
{
return 'slug';
}
2025-09-13 17:39:17 +03:00
/**
* Get the category that owns the book.
*/
public function category()
{
return $this->belongsTo(Category::class);
}
/**
* Get the summary associated with the book.
*/
public function summary()
{
return $this->hasOne(Summary::class);
}
2025-09-20 16:47:41 +03:00
/**
* The authors that belong to the book.
*/
public function authors()
{
return $this->belongsToMany(Author::class, 'author_book')->withTimestamps();
}
/**
* Users who saved this book to their readlist.
*/
public function savedByUsers()
{
return $this->belongsToMany(User::class, 'readlist_items')->withTimestamps();
}
/**
* Reports submitted for this book's summary.
*/
public function reports()
{
return $this->hasMany(SummaryReport::class);
}
/**
* Reviews left by users for this book's summary.
*/
public function reviews()
{
return $this->hasMany(SummaryReview::class);
}
2025-09-13 17:39:17 +03:00
}