diff --git a/app/Http/Livewire/Recipes.php b/app/Http/Livewire/Recipes.php index 01579c2..e135f80 100644 --- a/app/Http/Livewire/Recipes.php +++ b/app/Http/Livewire/Recipes.php @@ -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 . '%'); }); }