'date', 'gutenberg_id' => 'integer', ]; } /** * Use slug for route model binding and URL generation. */ public function getRouteKeyName(): string { return 'slug'; } /** * Scope a query to only include books from a specific source. */ public function scopeFromSource($query, string $source) { return $query->where('source', $source); } /** * Scope a query to only include manually added books. */ public function scopeManual($query) { return $query->where('source', 'manual'); } /** * Scope a query to only include Gutendex imported books. */ public function scopeGutendex($query) { return $query->where('source', 'gutendex'); } /** * Scope a query to only include books in a specific language. */ public function scopeInLanguage($query, string $language) { return $query->where('language', $language); } /** * 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); } }