N
N
nepster-web2016-04-08 18:06:02
Laravel
nepster-web, 2016-04-08 18:06:02

How to catch validation in laravel5?

There is a controller:

...
    public function index(TestService $service)
    {
        return view('test', [
            'name' => 'James'
        ]);
    }
    
    public function create(TestRequest $request)
    {
        echo '<pre>';
        print_r($request->all());
        die();
    }
...

There is a request:
class TestRequest extends Request
{
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'email'  => 'required'
        ];
    }

    public function sanitize()
    {
        return $this->all();
    }

}

And there is a view:
{{ form_open({'url': 'test/name'}) }}
        <div>
            {{ form_text('email') }}
        </div>
        <div>
            {{ form_submit('Send') }}
        </div>
    {{ form_close() }}

Actually, we can get the create action only if the validation was successful, everything is okay here. However, how to get the error data in the view using this method?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mokhirjon Naimov, 2016-04-09
@nepster-web

If I understood correctly, then you are here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question