Validating forms using form request of laravel
Created 7 years ago by ankitasoman

Hi @ryanthompson I am trying to develop a contact form using laravel's blade, and trying to validate it using form request. But i am getting empty results in error bag when I submit form with empty fields which are required. Is there anything like I cant use blade and form request with pyro??

piterden  —  7 years ago

You can easily validate with controller

    /**
     * Question from user
     *
     * @param  QuestionRepositoryInterface $questions The questions
     * @return Response
     */
    public function question(QuestionRepositoryInterface $questions)
    {
        if (!$this->request->ajax())
        {
            return redirect('/');
        }

        $validator = Validator::make($this->request->all(), [
            'email'   => 'required|email',
            'name'    => 'required',
            'city'    => 'required',
            'phone'   => 'required',
            'message' => 'required',
        ]);

        if ($validator->fails())
        {
            return $this->badResponse($validator->errors());
        }

        if ($question = $questions->create($this->request->only(
            [
                'email',
                'name',
                'city',
                'phone',
                'message',
            ]
        )))
        {
            return $this->goodResponse($question);
        }

        return $this->badResponse();
    }
ryanthompson  —  7 years ago

Form requests from Laravel should work normally.