gutendex processing implementation
This commit is contained in:
@@ -14,8 +14,23 @@ class Book extends Model
|
||||
'publication_date',
|
||||
'description',
|
||||
'category_id',
|
||||
'gutenberg_id',
|
||||
'source',
|
||||
'full_text_url',
|
||||
'language',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'publication_date' => 'date',
|
||||
'gutenberg_id' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Use slug for route model binding and URL generation.
|
||||
*/
|
||||
@@ -24,6 +39,38 @@ class Book extends Model
|
||||
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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user