Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel FormRequest get input value

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?

like image 257
ura ura Avatar asked Oct 10 '17 10:10

ura ura


1 Answers

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.

like image 199
madalinivascu Avatar answered Oct 30 '22 11:10

madalinivascu