1
0
Fork 0

app/Http/Livewire/Recipes.php: add spell relationship.

This commit is contained in:
Henrik Hautakoski 2021-07-08 13:26:52 +02:00
parent ff4f6b0612
commit 3b7f5d1501

View file

@ -5,6 +5,7 @@ namespace App\Http\Livewire;
use App\Models\Profession;
use App\Models\Recipe;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Livewire\Component;
@ -53,12 +54,16 @@ class Recipes extends Component
public function render()
{
$query = Recipe::select('recipes.*')
->join('items', 'items.id', '=', 'recipes.item_id')
->orderBy('items.name');
->leftJoin('items', 'items.id', '=', 'recipes.item_id')
->leftJoin('spells', 'spells.id', '=', 'recipes.spell_id')
->orderBy(DB::raw('(IF(`recipes`.`spell_id` IS NOT NULL, `spells`.`name`, `items`.`name`))'));
// Filter by name
if (strlen($this->name) >= 3) {
$query->whereHas('craft', function ($q) {
$query->whereHas('spell', function ($q) {
$q->where('name', 'LIKE', '%' . $this->name . '%');
})
->orWhereHas('craft', function($q) {
$q->where('name', 'LIKE', '%' . $this->name . '%');
});
}