forked from eatvio/eatvio-infra
reduce complexity php insight
This commit is contained in:
@@ -9,6 +9,7 @@ use Illuminate\Support\Str;
|
||||
use Illuminate\View\View;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
use App\Services\BlogPost\ListViewService;
|
||||
|
||||
class ListView extends Component
|
||||
{
|
||||
@@ -29,28 +30,11 @@ class ListView extends Component
|
||||
'author' => ['except' => ''],
|
||||
];
|
||||
|
||||
public function render(): View
|
||||
public function render(ListViewService $service): View
|
||||
{
|
||||
if ($this->author) {
|
||||
$author = $this->author;
|
||||
$user = User::find($author);
|
||||
$posts = $user ? $user->author_of_blog_post()->distinct() : [];
|
||||
} elseif ($this->tag) {
|
||||
$tagId = Str::of($this->tag)->split('/-/')->first();
|
||||
$posts = Tag::find($tagId)->blogPosts();
|
||||
} elseif ($this->search && mb_strlen($this->search) > 2) {
|
||||
$posts = BlogPost::where('title', 'rlike', $this->search);
|
||||
} else {
|
||||
$posts = (new BlogPost());
|
||||
}
|
||||
|
||||
if ($this->typeFilter === 'user') {
|
||||
$posts = $posts->whereRelation('author', 'is_consultant', false);
|
||||
}
|
||||
if ($this->typeFilter === 'consultant') {
|
||||
$posts = $posts->whereRelation('author', 'is_consultant', true);
|
||||
}
|
||||
$posts = $service->buildBlogPosts();
|
||||
|
||||
return view('livewire.blog-post.list-view', ['blogPosts' => $posts->orderBy('created_at', 'desc')->paginate(10)]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user