Add all files
This commit is contained in:
66
app/Livewire/Auth/Register.php
Normal file
66
app/Livewire/Auth/Register.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Auth;
|
||||
|
||||
use App\Attributes\DisabledIf;
|
||||
use App\Livewire\ComponentWithProperties;
|
||||
use App\Models\User;
|
||||
use App\Traits\Captchable;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
#[DisabledIf('registration_disabled')]
|
||||
class Register extends ComponentWithProperties
|
||||
{
|
||||
use Captchable;
|
||||
|
||||
public string $first_name = '';
|
||||
|
||||
public string $last_name = '';
|
||||
|
||||
public string $email = '';
|
||||
|
||||
public string $password = '';
|
||||
|
||||
public string $password_confirmation = '';
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->initializeProperties(null, User::class);
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return array_merge([
|
||||
'first_name' => 'required|string|max:255',
|
||||
'last_name' => 'required|string|max:255',
|
||||
'email' => 'required|email|max:255|unique:users',
|
||||
'password' => 'required|string|min:8|confirmed',
|
||||
], $this->getRulesForProperties());
|
||||
}
|
||||
|
||||
public function submit()
|
||||
{
|
||||
$validatedData = $this->validate();
|
||||
|
||||
$user = User::create([
|
||||
'first_name' => $this->first_name,
|
||||
'last_name' => $this->last_name,
|
||||
'email' => $this->email,
|
||||
'password' => Hash::make($this->password),
|
||||
]);
|
||||
|
||||
if (array_key_exists('properties', $validatedData)) {
|
||||
$this->updateProperties($user, $validatedData['properties']);
|
||||
}
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
return $this->redirectIntended(route('dashboard'), true);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('auth.register');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user