Validating forms using form request of laravel

ankitasoman - 3 months ago

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 - 3 months 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 - 3 months ago

Form requests from Laravel should work normally.