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');
|
||||
}
|
||||
}
|
||||
Reference in a new issue