-
resources/views/users/edit.blade.php
Open in GitHub@section('title') Edit Existing User @endsection @section('content-header') <x-content-header> Edit Existing User </x-content-header> @endsection <x-savings.content> <x-slot name="card_header"> <h3 class="card-title">Edit Existing User</h3> <a href="{{ route('users.index') }}" class="float-right">Back</a> </x-slot> <x-slot name="card_body"> <form method="POST" wire:submit.prevent="update"> @csrf <x-inputs.email key="user.email" placeholder="{{ trans('validation.attributes.email') }}" autofocus required="required" /> <x-inputs.dropdown key="user.role_id" :options="$roles" textField="name" required="required" /> <div class="row"> <div class="offset-8 col-4"> <x-inputs.button text="Save" class="btn-success" /> </div> </div> </form> </x-slot> </x-savings.content>
-
app/Http/Livewire/EditUserComponent.php
Open in GitHubuse App\Models\Role; use App\Models\User; use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Validation\Rule; use Livewire\Component; class EditUserComponent extends Component { use HasLivewireAuth; public User $user; public $roles; public function mount() { if ($this->user->isHimself(auth()->user())) { throw new AuthorizationException(); } } public function render() { $this->roles = Role::orderBy('name')->get(); return view('users.edit') ->extends('layouts.app'); } public function update() { $this->validate($this->rules()); $this->user->save(); msg_success('User has been successfully updated.'); return redirect()->route('users.index'); } protected function rules() { return [ 'user.email' => [ 'required', 'email', Rule::unique('users', 'email')->ignore($this->user->id), ], 'user.role_id' => [ 'required', 'exists:roles,id', ], ]; } }