Edit File: TagEdit.php
<?php namespace App\Livewire\Admin\Tag; use App\Models\Tag; use App\Models\History; use Livewire\Component; use Illuminate\Support\Str; use Illuminate\Validation\Rule; use Livewire\Attributes\Layout; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Session; class TagEdit extends Component { public string $name; public $tag; protected function rules() { return [ 'name' => [ 'required', 'string', 'max:100', Rule::unique("tags", "name")->ignore($this->tag->id), ], ]; } public function mount($id) { $this->tag = Tag::find($id); $this->name = $this->tag->name; } public function update() { $this->validate(); $this->tag->name = $this->name; $this->tag->slug = Str::slug("$this->name"); $this->tag->save(); History::create([ 'name' => Auth::user()->name, 'page' => 'Tag', 'title' => Auth::user()->name . ' Mengupdate Tag Baru ' . $this->tag->name, 'status' => 'info', ]); Session::flash('status', 'success'); Session::flash('message', 'Berhasil Mengupdate Tag ' . $this->tag->name); return redirect()->route("admin.tag.index"); } #[Layout("layouts.admin")] public function render() { return view('livewire.admin.tag.tag-edit'); } }
Back