Php Laravel-已检索模型后的函数where()
检索模型后,我可以使用where()函数或其他等效函数吗? 例如:Php Laravel-已检索模型后的函数where(),php,laravel,Php,Laravel,检索模型后,我可以使用where()函数或其他等效函数吗? 例如: $head = Equipment::where('user_id', $fighter->id)->where('lvl_after_reduction', '<=', $fighter->attributes->lvl)->where('durability', '>', 0) ->whereHas('item', funct
$head = Equipment::where('user_id', $fighter->id)->where('lvl_after_reduction', '<=', $fighter->attributes->lvl)->where('durability', '>', 0)
->whereHas('item', function ($q) {
$q->where('type_id', 1);
})->where('wear', 1)->first();
$torso = Equipment::where('user_id', $fighter->id)->where('lvl_after_reduction', '<=', $fighter->attributes->lvl)->where('durability', '>', 0)->whereHas('item', function ($q) {
$q->where('type_id', 2);
})->where('wear', 1)->first();
if ($torso == null)
$torso = Equipment::where('user_id', $fighter->id)->where('lvl_after_reduction', '<=', $fighter->attributes->lvl)->where('durability', '>', 0)->whereHas('item', function ($q) {
$q->where('type_id', 3);
})->where('wear', 1)->first();
$hands = Equipment::where('user_id', $fighter->id)->where('lvl_after_reduction', '<=', $fighter->attributes->lvl)->where('durability', '>', 0)->whereHas('item', function ($q) {
$q->where('type_id', 4);
})->where('wear', 1)->first();
$waist = Equipment::where('user_id', $fighter->id)->where('lvl_after_reduction', '<=', $fighter->attributes->lvl)->where('durability', '>', 0)->whereHas('item', function ($q) {
$q->where('type_id', 5);
})->where('wear', 1)->first();
$feet = Equipment::where('user_id', $fighter->id)->where('lvl_after_reduction', '<=', $fighter->attributes->lvl)->where('durability', '>', 0)->whereHas('item', function ($q) {
$q->where('type_id', 6);
})->where('wear', 1)->first();
$amulet = Equipment::where('user_id', $fighter->id)->where('lvl_after_reduction', '<=', $fighter->attributes->lvl)->where('durability', '>', 0)->whereHas('item', function ($q) {
$q->where('type_id', 8);
})->where('wear', 1)->first();
$first_ring = Equipment::where('user_id', $fighter->id)->where('lvl_after_reduction', '<=', $fighter->attributes->lvl)->where('durability', '>', 0)->whereHas('item', function ($q) {
$q->where('type_id', 9);
})->where('wear', 1)->first();
$secound_ring = Equipment::where('user_id', $fighter->id)->where('lvl_after_reduction', '<=', $fighter->attributes->lvl)->where('durability', '>', 0)->whereHas('item', function ($q) {
$q->where('type_id', 9);
})->where('wear', 2)->first();
$right_hand = Equipment::where('user_id', $fighter->id)->where('lvl_after_reduction', '<=', $fighter->attributes->lvl)->where('durability', '>', 0)->whereHas('item', function ($q) {
$q->whereIn('type_id', [10, 11]);
})->where('wear', 1)->first();
$head=设备::where('user\u id',$fighter->id)->where('lvl\u后减少','',0)
->其中有('项目',功能($q){
$q->where('type_id',1);
})->其中('wear',1)->first();
$torso=装备::其中('user_id',$fighter->id)->其中('lvl_减少后','',0)->何处有('item',功能($q){
$q->where('type_id',2);
})->其中('wear',1)->first();
如果($躯干==null)
$torso=装备::其中('user_id',$fighter->id)->其中('lvl_减少后','',0)->何处有('item',功能($q){
$q->where('type_id',3);
})->其中('wear',1)->first();
$hands=设备::where('user_id',$fighter->id)->where('lvl_后减少','',0)->where有('item',函数($q){
$q->where('type_id',4);
})->其中('wear',1)->first();
$WAILD=装备::其中('user_id',$fighter->id)->其中('lvl_后的_减少','',0)->何处有('item',功能($q){
$q->where('type_id',5);
})->其中('wear',1)->first();
$feet=设备::where('user_id',$fighter->id)->where('lvl_后减少','',0)->where有('item',函数($q){
$q->where('type_id',6);
})->其中('wear',1)->first();
$amulet=Equipment::where('user_id',$fighter->id)->where('lvl_after_reduction','',0)->where has('item',function($q){
$q->where('type_id',8);
})->其中('wear',1)->first();
$first\u ring=设备::where('user\u id',$fighter->id)->where('lvl\u after\u reduction','',0)->where has('item',function($q){
$q->where('type_id',9);
})->其中('wear',1)->first();
$secound\u ring=设备::where('user\u id',$fighter->id)->where('lvl\u after\u reduction','',0)->where has('item',function($q){
$q->where('type_id',9);
})->其中('wear',2)->first();
$right\u hand=装备::where('user\u id',$fighter->id)->where('lvl\u after\u reduction','',0)->where has('item',function($q){
$q->其中('type_id',[10,11]);
})->其中('wear',1)->first();
我可以将这些查询合并为一个查询吗?因为我每页都有很多对数据库的查询
对不起,我说的是英语。请将where子句组合成这样一个函数
$torso = Equipment::where([['user_id', $fighter->id], ['wear', 1]])->first();
它干净多了
是,在运行查询后,只要返回集合,就可以使用where
函数
乙二醇
你能行
Equipment::all();
然后将where
子句应用于它返回的集合。
这样的查询返回一个有说服力的集合。
转到本文档页面,查看所有可用于Elounce collection的功能
但是,使用where
子句返回以first()结尾的查询值是不可能的,因为它不返回集合