app/Http/Livewire/Recipes.php: add spell relationship.
This commit is contained in:
parent
ff4f6b0612
commit
3b7f5d1501
1 changed files with 8 additions and 3 deletions
|
|
@ -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 . '%');
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue