75 lines
1.4 KiB
PHP
75 lines
1.4 KiB
PHP
<?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',
|
|
];
|
|
|
|
/**
|
|
* Use slug for route model binding and URL generation.
|
|
*/
|
|
public function getRouteKeyName(): string
|
|
{
|
|
return 'slug';
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
}
|