Archived
1
0
Fork 0

app/Models/Recipe.php: in resolveRouteBinding() find record by spell slug first, then crafted item.

This commit is contained in:
Henrik Hautakoski 2021-07-08 13:24:12 +02:00
parent 8c3a5ddef1
commit ff4f6b0612

View file

@ -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;
}
/**