<?php
|
|
|
|
namespace App\Http\Livewire\Auth\Register;
|
|
|
|
use App\Providers\RouteServiceProvider;
|
|
use App\User;
|
|
use App\UserCategory;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Livewire\Component;
|
|
|
|
class Individual extends Component
|
|
{
|
|
/** @var string */
|
|
public $name = '';
|
|
|
|
/** @var string */
|
|
public $birthday = '';
|
|
|
|
/** @var string */
|
|
public $email = '';
|
|
|
|
public function updated($field)
|
|
{
|
|
$this->validateOnly($field, [
|
|
'email' => ['email', 'unique:users'],
|
|
'birthday' => ['date_format:d/m/Y'],
|
|
]);
|
|
}
|
|
|
|
public function register()
|
|
{
|
|
$this->validate([
|
|
'name' => ['required'],
|
|
'birthday' => ['required', 'date_format:d/m/Y'],
|
|
'email' => ['required', 'email', 'unique:users'],
|
|
]);
|
|
|
|
$user = User::create([
|
|
'name' => $this->name,
|
|
'email' => $this->email,
|
|
'category_id' => UserCategory::where('key', 'individual')->first()->id,
|
|
'birthday' => Carbon::createFromFormat('d/m/Y', $this->birthday),
|
|
]);
|
|
|
|
Auth::login($user, true);
|
|
|
|
redirect(route('home'));
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.auth.register.individual');
|
|
}
|
|
}
|