Edit File: VideoEdit.php
<?php namespace App\Livewire\Admin\Video; use App\Models\Anime; use App\Models\Video; use App\Models\History; use Livewire\Component; use Livewire\WithFileUploads; use Livewire\Attributes\Layout; use Livewire\Attributes\Validate; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Session; class VideoEdit extends Component { use WithFileUploads; public $anime_id; #[Validate('string|required|max:100')] public $anime_name; #[Validate(rule: 'nullable|mimes:mp4')] public $video_file; public $oldthumbnail; public $oldvideo; #[Validate('image|nullable|max:1024')] public $thumbnail; #[Validate('numeric|required')] public int $order; public $max_order; public $video; public $progress = 0; public function mount($id) { $this->video = Video::with("anime")->find($id); $this->anime_id = $this->video->anime->id; $this->max_order = count($this->video->anime->videos); $this->order = $this->video->order; $this->anime_name = $this->video->anime->name; $this->oldthumbnail = $this->video->thumbnail; $this->oldvideo = $this->video->video; } public function store() { $this->validate(); $anime = $this->video->anime; $sanitized_anime_name = $anime->name; $sanitized_anime_name = str_replace("?", "", $sanitized_anime_name); $sanitized_anime_name = str_replace(":", "-", $sanitized_anime_name); $this->video->name = $anime->name . " episode " . $this->order . " subtitle indonesia"; $this->video->anime_id = $this->anime_id; $order_check = Video::where("anime_id", $anime->id)->where("order", $this->order)->first(); if($order_check) { $order_check->order = $this->video->order; $order_check->name = $anime->name . " episode " . $order_check->order; $order_check->save(); $this->video->order = $this->order; } else { $this->video->order = $this->order; } if($this->thumbnail) { $extension = $this->thumbnail->getClientOriginalExtension(); $newname = $sanitized_anime_name . "-episode-" . $this->order . ".$extension"; $this->thumbnail->storeAs("anime/$sanitized_anime_name", $newname); $thumbnail_path = "/storage/anime/$sanitized_anime_name/$newname"; $this->video->thumbnail = $thumbnail_path; } if($this->video_file) { $extension = $this->video_file->getClientOriginalExtension(); $newname = $sanitized_anime_name . "-episode-" . $this->order . ".$extension"; $this->video_file->storeAs("anime/$sanitized_anime_name", $newname); $video_path = "/storage/anime/$sanitized_anime_name/$newname"; $this->video->video = $video_path; } $this->video->anime_id = intval($this->video->anime_id); $this->video->save(); $this->progress = 100; Session::flash('status', 'success'); Session::flash('message', 'Berhasil Mengupdate Episode ' . $this->video->order); History::create([ 'name' => Auth::user()->name, 'page' => 'Video', 'title' => Auth::user()->name . ' Mengupdate Anime ' . $this->video->name . " Episode " . $this->video->order, 'status' => 'success', ]); return redirect()->route("admin.video.index", $this->anime_id); } #[Layout("layouts.admin")] public function render() { return view('livewire.admin.video.video-edit'); } }
Back