1
0
Fork 0
mirror of https://github.com/archtechx/airwire-demo.git synced 2025-12-12 00:24:03 +00:00
airwire-demo/app/Airwire/CreateUser.php
2021-05-21 18:38:26 +02:00

46 lines
918 B
PHP

<?php
namespace App\Airwire;
use Airwire\Attributes\Wired;
use Airwire\Component;
use App\Models\User;
use Exception;
class CreateUser extends Component
{
public bool $strictValidation = false;
#[Wired]
public string $name = '';
#[Wired]
public string $email = '';
#[Wired]
public string $password = '';
#[Wired]
public string $password_confirmation = '';
public function rules()
{
return [
'name' => ['required', 'min:5', 'max:25', 'unique:users'],
'email' => ['required', 'unique:users'],
'password' => ['required', 'min:8', 'confirmed'],
];
}
#[Wired]
public function create(): User
{
$user = User::create($this->validated());
$this->meta('notification', __('users.created', ['id' => $user->id, 'name' => $user->name]));
$this->reset();
return $user;
}
}