Can I use the function where() or some equivalent after the model has already been retrieved? For example:
$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();
Can I combine these queries into one? Because I have a lot of queries to database per page.
Sorry for my english.