04 10 2023 snapshot

This commit is contained in:
Anatoliy Poloz
2023-10-04 17:57:09 +03:00
parent 1e546fa48e
commit 09a00744a0
441 changed files with 41582 additions and 254079 deletions

View File

@@ -0,0 +1,52 @@
<?php
namespace App\Livewire\BlogPost;
use Livewire\Component;
use Livewire\WithPagination;
use App\Models\BlogPost;
use App\Models\User;
use App\Models\Tag;
use Illuminate\Support\Str;
class ListView extends Component
{
use WithPagination;
public $search = "";
public $typeFilter = "all";
public $tag = '';
public $author;
protected $queryString = [
'search' => ['except' => ''],
'typeFilter' => ['except' => 'all'],
'tag' => ['except' => ''],
'author' => ['except' => '']
];
public function render()
{
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);
}
return view('livewire.blog-post.list-view', ['blogPosts' => $posts->orderBy('created_at', 'desc')->paginate(10)]);
}
}