我有两个模型共用一张表。
表名为books,我通过一个名为type
的属性来区分普通书籍和小说。
Book模型:
class Book extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'books';
}
新颖的模型
class Novel extends Book
{
protected $table = 'books';
// Is such a method available?
protected function someMethodToOverride()
{
$this->where('type', 'novel');
}
}
What I want to achieve here is
$results = Novel::where('title', 'LIKE', '%' . $title . '%')->get();
从这个查询中,我希望它预设条件。
where('type', 'novel')
有没有可以重写的函数来实现这个功能?