💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
### 定义范围查询 范围查询可以让您轻松的重复利用模型的查询逻辑。要设定范围查询,只要定义有 `scope` 前缀的模型方法: ~~~ ~~~ class User extends Model { public function scopePopular($query) { return $query->where('votes', '>', 100); } public function scopeWomen($query) { return $query->whereGender('W'); } } ~~~ ~~~ ### 使用范围查询 ~~~ ~~~ $users = User::popular()->women()->orderBy('created_at')->get(); ~~~ ~~~ ### 动态范围查询 有时您可能想要定义可接受参数的范围查询方法。只要把参数加到方法里: ~~~ ~~~ class User extends Model { public function scopeOfType($query, $type) { return $query->whereType($type); } } ~~~ ~~~ 然后把参数值传到范围查询方法调用里: ~~~ ~~~ $users = User::ofType('member')->get(); ~~~ ~~~