From ff4f6b061276381d3f77510c3e154818a56a50bd Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Thu, 8 Jul 2021 13:24:12 +0200 Subject: [PATCH] app/Models/Recipe.php: in resolveRouteBinding() find record by spell slug first, then crafted item. --- app/Models/Recipe.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/Models/Recipe.php b/app/Models/Recipe.php index d45229c..5352afb 100644 --- a/app/Models/Recipe.php +++ b/app/Models/Recipe.php @@ -55,9 +55,18 @@ class Recipe extends Model */ public function resolveRouteBinding($value, $field = null) { - return $this->whereHas('craft', function ($q) use ($value) { + $spell = $this->whereHas('spell', function ($q) use ($value) { $q->where('slug', $value); - })->firstOrFail(); + })->first(); + + // Fallback on crafted item. + if (!$spell) { + return $this->whereHas('craft', function ($q) use ($value) { + $q->where('slug', $value); + })->first(); + } + + return $spell; } /**