Edit File: CommentIndex.php
<?php namespace App\Livewire\Admin\Comment; use App\Models\Comment; use App\Models\History; use Livewire\Component; use Livewire\WithPagination; use Livewire\Attributes\Layout; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Session; class CommentIndex extends Component { use WithPagination; public $important = true; public function toggleImportant() { $this->important = !$this->important; } public function delete($id) { $comment = Comment::with("user")->find($id); Session::flash('status', 'success'); Session::flash('message', 'Berhasil Menghapus Komentar'); History::create([ 'name' => Auth::user()->name, 'page' => 'Comment', 'title' => Auth::user()->name . ' Menghapus Komentar ' . $comment->user->username, 'status' => 'danger', ]); if($comment) { $comment->delete(); } return redirect()->route("admin.comment.index"); } #[Layout("layouts.admin")] public function render() { return view('livewire.admin.comment.comment-index', [ 'comments' => Comment::with("user", 'anime')->orderByDesc("created_at")->paginate(50), ]); } }
Back