Path : /var/www/html/phkaynews-v2/app/Http/Livewire/Frontend/ |
B-Con CMD Config cPanel C-Rdp D-Log Info Jump Mass Ransom Symlink vHost Zone-H |
Current File : /var/www/html/phkaynews-v2/app/Http/Livewire/Frontend/ByCategoryPage.php |
<?php namespace App\Http\Livewire\Frontend; use App\Models\Advertise; use App\Models\Post; use Livewire\Component; use App\Models\Category; use Livewire\WithPagination; class ByCategoryPage extends Component { use WithPagination; protected $paginationTheme = 'bootstrap'; public $category; public $readyToLoadTopPost = false; public $readyToLoadPost = false; public $readyToLoadNewPost = false; public $readyToLoadPopularPost = false; public $readyToLoadAds1 = false; public $readyToLoadAds2 = false; public function mount($slug) { $this->category = Category::where('slug', $slug)->firstOrFail(); } public function TopPostLoad() { $this->readyToLoadTopPost = true; } public function PostLoad() { $this->readyToLoadPost = true; } public function NewPostLoad() { $this->readyToLoadNewPost = true; } public function PopularPostLoad() { $this->readyToLoadPopularPost = true; } public function AdsItem1Load() { $this->readyToLoadAds1 = true; } public function AdsItem2Load() { $this->readyToLoadAds2 = true; } public function render() { $id = $this->category->id; $postTop = Post::publiced()->whereHas('post_categories', function ($query) use ($id) { $query->where('category_id', $id); })->orderBy('id', 'desc')->take(2)->get(); $postTopId = $postTop->pluck('id'); $posts = Post::publiced()->whereHas('post_categories', function ($query) use ($id) { $query->where('category_id', $id); })->whereNotIn('id', $postTopId)->orderBy('id', 'desc')->paginate(20); $popularPosts = Post::publiced()->orderBy('view', 'desc')->inRandomOrder()->take(3)->get(); $newPost = Post::publiced()->orderBy('id', 'desc')->take(3)->get(); $ads_right = Advertise::where('type', config('ads.key.ar'))->inRandomOrder()->take(1)->first(); $ads_category = Advertise::where('type', config('ads.key.cp'))->inRandomOrder()->take(1)->first(); $ads_item1 = Advertise::where('type', config('ads.key.ci'))->inRandomOrder()->take(1)->first(); if (Advertise::where('type', config('ads.key.ci'))->count() >= 2) { $ads_item2 = Advertise::where('type', config('ads.key.ci'))->whereNotIn('id', [$ads_item1->id])->inRandomOrder()->first(); } else { $ads_item2 = []; } return view('livewire.frontend.by-category-page', [ 'posts' => $this->readyToLoadPost ? $posts : [], 'countPost' => $posts->count(), 'popularPosts' => $popularPosts, 'count_popular_posts' => $popularPosts->count(), 'newPost' => $newPost, 'countNewPost' => $newPost->count(), 'postTop' => $this->readyToLoadTopPost ? $postTop : [], 'countPostTop' => $postTop->count(), 'advertise' => $ads_category, 'ads_item1' => $this->readyToLoadAds1 ? $ads_item1 : null, 'ads_item2' => $this->readyToLoadAds2 ? $ads_item2 : null, 'ads_right' => $ads_right ]); } }