Edit File: NationIndex.php
<?php namespace App\Livewire\Admin\Nation; use App\Models\Nation; use App\Models\History; use Livewire\Component; use Livewire\Attributes\Layout; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Session; use Livewire\WithPagination; class NationIndex extends Component { public $nations; public function mount() { $this->refreshContent(); } public function delete($id) { $nation = Nation::find($id); Session::flash('status', 'success'); Session::flash('message', 'Berhasil Menghapus Negara ' . $nation->name); History::create([ 'name' => Auth::user()->name, 'page' => 'Nations', 'title' => Auth::user()->name . ' Menghapus Negara ' . $nation->name, 'status' => 'danger', ]); $nation->delete(); $this->refreshContent(); } public function refreshContent() { $this->nations = Nation::orderBy("name")->get(); } #[Layout("layouts.admin")] public function render() { return view('livewire.admin.nation.nation-index'); } }
Back