I try to use FormRequest:
class RegistrationForm extends FormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
return [
'name'=>'required',
'email'=>'required|email',
'password'=>'required|confirmed'
];
}
public function persist(){
$user=new User();
$user->name=$this->only(['name']);
$user->email=$this->only(['email']);
dd($this->only(['password']);
auth()->login($user);
}
}
I need get in persist() method inputs value from my requst. I tried to get 'password' value, but I got array. How can I get input value like a string?
You can get the values using the input()
function:
public function persist() {
$user = new User();
$user->name = $this->input('name');
$user->email = $this->input('email');
dd($this->input('password'));
auth()->login($user);
}
Ps: I suggest you do your logic in the controller not in the request class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With