Edit File: AnimeShow.php
<?php namespace App\Livewire\Show; use App\Models\Page; use App\Models\User; use App\Models\Anime; use Livewire\Component; use Livewire\Attributes\Layout; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Session; class AnimeShow extends Component { public $anime; public $random_anime; public $first_episode; public $latest_episode; public $followState = false; public $user; public $expanded = false; public $showReadMore = false; public bool $video_open = false; public function mount($slug) { $this->anime = Anime::with("type", 'season', 'nation')->where("slug", $slug)->first(); if ($this->anime) { $this->random_anime = Anime::with("tags")->where("id", "!=", $this->anime->id)->where("is_film", $this->anime->is_film)->inRandomOrder()->limit(6)->get(); $this->latest_episode = $this->anime->videos()->orderByDesc("order")->first(); $this->first_episode = $this->anime->videos()->orderBy("order")->first(); if(Auth::check()) { $this->user = User::with("followedAnimes")->find(Auth::id()); $this->followState = $this->user->followedAnimes()->where("anime_id", $this->anime->id)->exists(); } else { $this->followState = false; } $this->showReadMore = strlen($this->anime->short_description) > 200; } } public function toggleVideo() { $this->video_open = !$this->video_open; } public function toggleFollow(Anime $anime) { if(Auth::check()) { $this->followState = !$this->followState; if ($this->followState == true) { $this->user->followedAnimes()->attach($this->anime->id); } else { $this->user->followedAnimes()->detach($this->anime->id); } } else { Session::flash('status', 'success'); Session::flash('message', 'Please Register First To Enable Follow Feature'); return redirect()->route("register"); } } public function switchExpanded() { $this->expanded = !$this->expanded; } #[Layout("layouts.guest")] public function render() { return view('livewire.show.anime-show'); } }
Back