119 lines
3.8 KiB
PHP
119 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use App\Models\Blog;
|
|
use Livewire\Component;
|
|
use App\Models\Category;
|
|
use Illuminate\Http\Request;
|
|
use Livewire\Attributes\Layout;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class Home2 extends Component
|
|
{
|
|
|
|
|
|
public $image;
|
|
public $blogs;
|
|
public $news;
|
|
public $blogs2;
|
|
public $blog_array = [];
|
|
public $news_array = [];
|
|
public $categories = [];
|
|
public $categorieNews = [];
|
|
public $lastNewsPosts = [];
|
|
public $lastNewsArticles = [];
|
|
public $lightmags = [];
|
|
public $lightnews = [];
|
|
|
|
public $selectedCategoryPosts = null;
|
|
public $selectedCategoryNews = null;
|
|
public $selectedRoutePosts = null;
|
|
public $selectedRouteNews = null;
|
|
|
|
public function mount(Request $request)
|
|
{
|
|
$allBlogs = Blog::where('status', 1)->orderBy('published_at', 'desc')->get();
|
|
|
|
$this->lightmags = $allBlogs->whereNull('notBlog')->take(50);
|
|
|
|
$this->lightnews = $allBlogs->where('notBlog', 1)->take(50);
|
|
$allCategroy = Category::where('status', 1)->get();
|
|
$this->blogs2 = Blog::where('status', 1)->where('notBlog', null)->where('chosen', 1)->orderBy('created_at', 'desc')->get()->take(5);
|
|
|
|
$this->lastNewsPosts = $allBlogs->whereNull('notBlog')->take(4);
|
|
$this->lastNewsArticles = $allBlogs->where('notBlog', 1)->take(4);
|
|
|
|
$this->blogs = $allBlogs->where('chosen', 0)->where('notBlog', null);
|
|
$this->news = $allBlogs->where('chosen', 0)->where('notBlog', 1);
|
|
$this->categories = $allCategroy->where('parent_below', null)->where('parent_id', null)->where('parent', null);
|
|
$this->categorieNews = $allCategroy->where('is_news', 1)->where('parent_below', null)->where('parent_id', '!=', null)->where('parent', null);
|
|
}
|
|
|
|
public function selectCategory($categoryId, $type = 'posts')
|
|
{
|
|
$this->selectedCategoryPosts = $categoryId;
|
|
$category = Category::find($categoryId);
|
|
if (isset($category)) {
|
|
$this->selectedRoutePosts = route('CategoryBlog.index', ['slug' => $category->slug]) . "/";
|
|
}
|
|
}
|
|
public function selectCategoryNews($categoryId, $type = 'news')
|
|
{
|
|
$this->selectedCategoryNews = $categoryId;
|
|
$category = Category::find($categoryId);
|
|
if (isset($category)) {
|
|
$this->selectedRouteNews = route('NewsCategory.show', ['slug' => $category->slug]) . "/";
|
|
}
|
|
}
|
|
|
|
public function resetCategory($type = 'posts')
|
|
{
|
|
$this->selectedRoutePosts = null;
|
|
$this->selectedCategoryPosts = null;
|
|
}
|
|
|
|
public function resetCategoryNews($type = 'news')
|
|
{
|
|
$this->selectedRouteNews = null;
|
|
$this->selectedCategoryNews = null;
|
|
}
|
|
|
|
public function getCategoryItems($categoryId = null, $type = 'posts')
|
|
{
|
|
if ($type === 'posts') {
|
|
$query = Blog::where('status', 1)->whereNull('notBlog');
|
|
|
|
if ($categoryId) {
|
|
$query->where(function($q) use ($categoryId) {
|
|
$q->where('category_id', $categoryId)
|
|
->orWhereJsonContains('category_array', (string)$categoryId);
|
|
});
|
|
}
|
|
|
|
return $query->orderByDesc('published_at')
|
|
->take(4)
|
|
->get();
|
|
} else {
|
|
$query = Blog::where('status', 1)->where('notBlog', 1);
|
|
|
|
if ($categoryId) {
|
|
$query->where(function($q) use ($categoryId) {
|
|
$q->where('category_id', $categoryId)
|
|
->orWhereJsonContains('category_array', (string)$categoryId);
|
|
});
|
|
}
|
|
|
|
return $query->orderByDesc('published_at')
|
|
->take(4)
|
|
->get();
|
|
}
|
|
}
|
|
|
|
#[Layout('components.layouts.app2')]
|
|
public function render()
|
|
{
|
|
return view('livewire.home2');
|
|
}
|
|
}
|