livewire: adding Account form
This commit is contained in:
parent
6dfa61348e
commit
291d6bd128
2 changed files with 106 additions and 0 deletions
75
app/Http/Livewire/Form/AccountForm.php
Normal file
75
app/Http/Livewire/Form/AccountForm.php
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Form;
|
||||
|
||||
use App\Models\Admin;
|
||||
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Http\Livewire\Traits\Alert;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class AccountForm extends Component
|
||||
{
|
||||
use Alert;
|
||||
|
||||
public $username;
|
||||
|
||||
public $password;
|
||||
|
||||
public $password_current;
|
||||
|
||||
public $password_confirmation;
|
||||
|
||||
protected $validationAttributes = [
|
||||
'password_current' => 'current password',
|
||||
'password' => 'new password',
|
||||
];
|
||||
|
||||
public function mount(Request $request)
|
||||
{
|
||||
$this->record = $request->user();
|
||||
|
||||
$this->username = $this->record->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation rules
|
||||
*/
|
||||
protected function rules()
|
||||
{
|
||||
return [
|
||||
'password_current' => [ 'required', 'password' ],
|
||||
'password' => [ Password::min(8)->letters()->mixedCase()->numbers(), 'confirmed' ]
|
||||
];
|
||||
}
|
||||
|
||||
public function updated($property, $value)
|
||||
{
|
||||
if ($property == 'password_confirmation') {
|
||||
$property = 'password';
|
||||
}
|
||||
|
||||
$this->validateOnly($property);
|
||||
}
|
||||
|
||||
public function submit()
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
$this->record->password = Hash::make($this->password);
|
||||
$this->record->save();
|
||||
|
||||
return redirect()->route('admin')
|
||||
->with('info', __('Password was successfully updated.'));
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('form.account')
|
||||
->layout('layouts.admin');
|
||||
}
|
||||
}
|
||||
31
resources/views/form/account.blade.php
Normal file
31
resources/views/form/account.blade.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<div class="space-y-4">
|
||||
|
||||
<x-header>{{ __('Edit account') }}</x-header>
|
||||
|
||||
<form class="space-y-4" wire:submit.prevent="submit">
|
||||
|
||||
<div>
|
||||
<x-ignite-label for="username">{{ __('Username') }}</x-ignite-label>
|
||||
<x-ignite-input name="username" value="{{ $username }}" disabled />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<x-ignite-label for="password_current">{{ __('Current Password') }}</x-ignite-label>
|
||||
<x-ignite-password name="password_current" wire:model="password_current" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<x-ignite-label for="password">{{ __('New Password') }}</x-ignite-label>
|
||||
<x-ignite-password name="password" wire:model="password" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<x-ignite-label for="password_confirmation">{{ __('Confirm Password') }}</x-ignite-label>
|
||||
<x-ignite-password name="password_confirmation" wire:model="password_confirmation" />
|
||||
</div>
|
||||
|
||||
<x-button type="info">{{ __('Save') }}</x-button>
|
||||
<x-button href="{{ route('admin') }}" type="warning">{{ __('Back') }}</x-button>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue