forked from eatvio/eatvio-infra
31 lines
735 B
PHP
31 lines
735 B
PHP
<?php
|
|
|
|
namespace App\Services\Strategy\Criteried;
|
|
|
|
use App\Models\BlogPost;
|
|
use App\Models\Recipe;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
|
|
|
class AuthorCriteriaStrategy implements CriteriaStrategy
|
|
{
|
|
public function __construct(private User $author)
|
|
{
|
|
}
|
|
|
|
public function getBlogPosts(): Builder|BlogPost|MorphToMany|array
|
|
{
|
|
$user = User::find($this->author);
|
|
|
|
return $user ? $user->author_of_blog_post()->distinct() : [];
|
|
}
|
|
|
|
public function getRecipes(): Builder|Recipe|MorphToMany|array
|
|
{
|
|
$user = User::find($this->author);
|
|
|
|
return $user ? $user->author_of_recipe()->distinct() : [];
|
|
}
|
|
}
|