Edit File: NationEdit.php
<?php namespace App\Livewire\Admin\Nation; use App\Models\Nation; use App\Models\History; use Livewire\Component; use Illuminate\Support\Str; use Livewire\Attributes\Layout; use Livewire\Attributes\Validate; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Session; class NationEdit extends Component { public $nation; #[Validate("string|max:80")] public string $name; #[Validate("string|max:80")] public string $alias; public function mount($id) { $this->nation = Nation::find($id); $this->name = $this->nation->name; $this->alias = $this->nation->alias; } public function update() { $this->validate(); $this->nation->name = $this->name; $this->nation->slug = Str::slug($this->name); $this->nation->alias = $this->alias; $this->nation->save(); History::create([ 'name' => Auth::user()->name, 'page' => 'Nation', 'title' => Auth::user()->name . ' Mengupdate Nation ' . $this->nation->name, 'status' => 'info', ]); Session::flash('status', 'success'); Session::flash('message', 'Berhasil Mengupdate Nation ' . $this->nation->name); return redirect()->route("admin.nation.index"); } #[Layout("layouts.admin")] public function render() { return view('livewire.admin.nation.nation-edit'); } }
Back