Skip to content

Commit

Permalink
Return slugs in find methods (#443)
Browse files Browse the repository at this point in the history
* Return slugs in find methods

I assume if a "name" is in slug format, that the slug will be the same as the name?!

Assumption aside, I don't see any side effects for methods like `findOrCreateFromString` which call these changed functions.

* Revert changes to test tests :S

* Allow find strings methods to search via slug as well

Switch to anonymous migration and void return type for up method (#440)

Method for reversing migrations (#442)

* Method for reversing migrations

* Add missing return type declaration

wip

Update README.md

fix tests

Fix styling

Update CHANGELOG

Return slugs in find methods

I assume if a "name" is in slug format, that the slug will be the same as the name?!

Assumption aside, I don't see any side effects for methods like `findOrCreateFromString` which call these changed functions.

Revert changes to test tests :S

allow find from string methods to search slug field

Co-authored-by: ziming <[email protected]>
  • Loading branch information
falconsmilie and ziming authored Jan 25, 2023
1 parent fe7d796 commit 490a882
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,17 @@ public static function getWithType(string $type): DbCollection
{
return static::withType($type)->get();
}

public static function findFromString(string $name, string $type = null, string $locale = null)
{
$locale = $locale ?? static::getLocale();

return static::query()
->where("name->{$locale}", $name)
->where('type', $type)
->where(function($query) use ($name, $locale) {
$query->where("name->{$locale}", $name)
->orWhere("slug->{$locale}", $name);
})
->first();
}

Expand All @@ -81,6 +84,7 @@ public static function findFromStringOfAnyType(string $name, string $locale = nu

return static::query()
->where("name->{$locale}", $name)
->orWhere("slug->{$locale}", $name)
->get();
}

Expand Down

0 comments on commit 490a882

Please sign in to comment.