Skip to content

Commit

Permalink
feat: update typing query to use hasTyping
Browse files Browse the repository at this point in the history
  • Loading branch information
ScuffedNewt committed Jul 20, 2024
1 parent 56f6148 commit 88bff84
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
7 changes: 7 additions & 0 deletions app/Models/Element/Typing.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ public static function hasTyping($object) {
return self::where('typing_model', get_class($object))->where('typing_id', $object->id)->exists();
}

/**
* gets the typing of a certain object.
*/
public static function getTyping($object) {
return self::where('typing_model', get_class($object))->where('typing_id', $object->id)->first();
}

/**
* returns a collection of element objects from the typing.
*/
Expand Down
12 changes: 3 additions & 9 deletions resources/views/character/_image_info.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,12 @@
@php
// check if there is a type for this object if not passed
// for characters first check subtype (since it takes precedence)
$type = \App\Models\Element\Typing::where('typing_model', 'App\Models\Character\CharacterImage')
->where('typing_id', $image->id)
->first();
$type = \App\Models\Element\Typing::hasTyping($image) ? \App\Models\Element\Typing::getTyping($image) : null;
if (!isset($type) && $image->subtype_id) {
$type = \App\Models\Element\Typing::where('typing_model', 'App\Models\Species\Subtype')
->where('typing_id', $image->subtype_id)
->first();
$type = \App\Models\Element\Typing::hasTyping($image->subtype) ? \App\Models\Element\Typing::getTyping($image->subtype) : null;
}
if (!isset($type)) {
$type = \App\Models\Element\Typing::where('typing_model', 'App\Models\Species\Species')
->where('typing_id', $image->species_id)
->first();
$type = \App\Models\Element\Typing::hasTyping($image->species) ? \App\Models\Element\Typing::getTyping($image->species) : null;
}
$type = $type ?? null;
@endphp
Expand Down

0 comments on commit 88bff84

Please sign in to comment.