diff --git a/app/Livewire/BlogPost/ListView.php b/app/Livewire/BlogPost/ListView.php index 99558da..7064835 100644 --- a/app/Livewire/BlogPost/ListView.php +++ b/app/Livewire/BlogPost/ListView.php @@ -2,14 +2,11 @@ namespace App\Livewire\BlogPost; -use App\Models\BlogPost; -use App\Models\Tag; use App\Models\User; -use Illuminate\Support\Str; +use App\Services\BlogPost\ListViewService; use Illuminate\View\View; use Livewire\Component; use Livewire\WithPagination; -use App\Services\BlogPost\ListViewService; class ListView extends Component { @@ -36,5 +33,4 @@ class ListView extends Component return view('livewire.blog-post.list-view', ['blogPosts' => $posts->orderBy('created_at', 'desc')->paginate(10)]); } - } diff --git a/app/Livewire/Recipe/ListView.php b/app/Livewire/Recipe/ListView.php index 6d2e62b..42e2576 100644 --- a/app/Livewire/Recipe/ListView.php +++ b/app/Livewire/Recipe/ListView.php @@ -2,16 +2,11 @@ namespace App\Livewire\Recipe; -use App\Models\Recipe; -use App\Models\Tag; use App\Models\User; -use Illuminate\Database\Eloquent\Relations\Relation; -use Illuminate\Database\Eloquent\Collection; -use Illuminate\Support\Str; +use App\Services\Recipe\ListViewService; use Illuminate\View\View; use Livewire\Component; use Livewire\WithPagination; -use App\Services\Recipe\ListViewService; class ListView extends Component { diff --git a/app/Services/BlogPost/ListViewService.php b/app/Services/BlogPost/ListViewService.php index e8f2cb8..c1e78c0 100644 --- a/app/Services/BlogPost/ListViewService.php +++ b/app/Services/BlogPost/ListViewService.php @@ -6,9 +6,8 @@ use App\Livewire\BlogPost\ListView; use App\Models\BlogPost; use App\Models\Tag; use App\Models\User; -use Illuminate\Database\Eloquent\Relations\MorphToMany; -use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Relations\MorphToMany; use Illuminate\Support\Str; class ListViewService diff --git a/app/Services/Recipe/ListViewService.php b/app/Services/Recipe/ListViewService.php index af056f9..230f90f 100644 --- a/app/Services/Recipe/ListViewService.php +++ b/app/Services/Recipe/ListViewService.php @@ -6,11 +6,9 @@ use App\Livewire\Recipe\ListView; use App\Models\Recipe; use App\Models\Tag; use App\Models\User; -use Illuminate\Database\Eloquent\Relations\Relation; -use Illuminate\Database\Eloquent\Collection; -use Illuminate\Support\Str; -use Illuminate\Database\Eloquent\Relations\MorphToMany; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Relations\MorphToMany; +use Illuminate\Support\Str; class ListViewService { @@ -28,6 +26,28 @@ class ListViewService return $this->getSecondaryCriteriedRecipes($recipes); } + public function getTagsCollection(): array + { + return Recipe::all()->map( + fn ($r) => [ + $r->type, + $r->tags->map(fn ($t) => $t->id . '-' . $t->name)->all(), + ] + )->reduce(function ($acc, $item) { + [$type, $tagNames] = $item; + + foreach ($tagNames as $name) { + if (isset($acc[$type][$name])) { + $acc[$type][$name] += 1; + } else { + $acc[$type][$name] = 1; + } + } + + return $acc; + }); + } + private function getPrimaryCriteriedRecipes(): Builder|Recipe|MorphToMany|array { if ($this->parentState->author) { @@ -40,7 +60,7 @@ class ListViewService return $this->getSearchRecipes(); } - return (new Recipe()); + return new Recipe(); } private function getSecondaryCriteriedRecipes(Builder|Recipe|MorphToMany|array $recipes): Recipe @@ -73,26 +93,4 @@ class ListViewService { return Recipe::where('title', 'rlike', $this->parentState->search); } - - public function getTagsCollection(): array - { - return Recipe::all()->map( - fn($r) => [ - $r->type, - $r->tags->map(fn($t) => $t->id . '-' . $t->name)->all(), - ] - )->reduce(function ($acc, $item) { - [$type, $tagNames] = $item; - - foreach ($tagNames as $name) { - if (isset($acc[$type][$name])) { - $acc[$type][$name] += 1; - } else { - $acc[$type][$name] = 1; - } - } - - return $acc; - }); - } } diff --git a/app/Services/RegistrationRuleSet.php b/app/Services/RegistrationRuleSet.php index 91596e5..df33072 100644 --- a/app/Services/RegistrationRuleSet.php +++ b/app/Services/RegistrationRuleSet.php @@ -97,6 +97,7 @@ class RegistrationRuleSet * Transform the given value. * * @param mixed $value + * * @return mixed */ protected static function transform($value)