Skull™👻
Registration Page with custom Field
The registration system works, if I remove the "invite code" input required.
however, I need this field for my project concept to work. and this is causing me problems because I can't find any way to make it work.
10 replies
Registration Page with custom Field
<?php
namespace App\Filament\Affiliate\Pages\Auth;
use App\Models\User;
use Filament\Forms\Components\Component;
use Filament\Forms\Components\Field;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Pages\Auth\Register as AuthRegister;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Validation\Rules\Exists;
class Register extends AuthRegister
{
public function getTitle(): string | Htmlable
{
return 'Cadastro';
}
public function getHeading(): string | Htmlable
{
return 'Cadastro';
}
public function form(Form $form): Form
{
return $form
->schema([
$this->getInviteCodeFormComponent(),
$this->getNameFormComponent(),
$this->getDocumentFormComponent(),
$this->getPhoneFormComponent(),
$this->getEmailFormComponent(),
$this->getPasswordFormComponent(),
$this->getPasswordConfirmationFormComponent(),
])
->statePath('data');
}
protected function getDocumentFormComponent(): Component
{
return TextInput::make('document')
->label('CPF')
->mask('999.999.999-99')
->required()
->maxLength(14)
->unique($this->getUserModel())
->helperText('Seu CPF será usado para recebimentos dos pagamentos. 999.999.999-99');
}
protected function getPhoneFormComponent(): Component
{
return TextInput::make('phone')
->label('Telefone')
->mask('(99) 99999-9999')
->required()
->maxLength(15)
->unique($this->getUserModel())
->helperText('Informe o DDD e o número do seu telefone celular. (99) 99999-9999');
}
protected function getInviteCodeFormComponent(): Component
{
return Field::make('ref_code')
->label('Invite Code')
->helperText('Inout your invite code here.')
->exists(modifyRuleUsing: function (Exists $rule) {
$rule->where(function ($query, $value) {
// Check if the Invite Code exists
$search_owner = User::where('ref_code', $value)
->where('manager_level', 2)
->first();
if (!$search_owner) {
// If the invite code does not exist, show an error message
$query->fail('Invalid Manager Code.');
}
// If the invite code exists, then add the "$search_owner->id" to your "affiliate_id" user registration.
});
});
}
}
<?php
namespace App\Filament\Affiliate\Pages\Auth;
use App\Models\User;
use Filament\Forms\Components\Component;
use Filament\Forms\Components\Field;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Pages\Auth\Register as AuthRegister;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Validation\Rules\Exists;
class Register extends AuthRegister
{
public function getTitle(): string | Htmlable
{
return 'Cadastro';
}
public function getHeading(): string | Htmlable
{
return 'Cadastro';
}
public function form(Form $form): Form
{
return $form
->schema([
$this->getInviteCodeFormComponent(),
$this->getNameFormComponent(),
$this->getDocumentFormComponent(),
$this->getPhoneFormComponent(),
$this->getEmailFormComponent(),
$this->getPasswordFormComponent(),
$this->getPasswordConfirmationFormComponent(),
])
->statePath('data');
}
protected function getDocumentFormComponent(): Component
{
return TextInput::make('document')
->label('CPF')
->mask('999.999.999-99')
->required()
->maxLength(14)
->unique($this->getUserModel())
->helperText('Seu CPF será usado para recebimentos dos pagamentos. 999.999.999-99');
}
protected function getPhoneFormComponent(): Component
{
return TextInput::make('phone')
->label('Telefone')
->mask('(99) 99999-9999')
->required()
->maxLength(15)
->unique($this->getUserModel())
->helperText('Informe o DDD e o número do seu telefone celular. (99) 99999-9999');
}
protected function getInviteCodeFormComponent(): Component
{
return Field::make('ref_code')
->label('Invite Code')
->helperText('Inout your invite code here.')
->exists(modifyRuleUsing: function (Exists $rule) {
$rule->where(function ($query, $value) {
// Check if the Invite Code exists
$search_owner = User::where('ref_code', $value)
->where('manager_level', 2)
->first();
if (!$search_owner) {
// If the invite code does not exist, show an error message
$query->fail('Invalid Manager Code.');
}
// If the invite code exists, then add the "$search_owner->id" to your "affiliate_id" user registration.
});
});
}
}
10 replies