R
R
Ruslan Absalyamov2018-10-13 13:17:05
Laravel
Ruslan Absalyamov, 2018-10-13 13:17:05

How to write validation for a form?

There is validation, you need to display fields that did not pass the test

$errors = $request->validate([
            'username' => 'required|string',
            'password' => 'required|string'
        ]);

Then, with an error, I render an html page, the main page. if, of course, substitute errors(), then it asks to be an array. Then I got into a stupor how to apply this validation

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
k2lhu, 2018-10-13
@k2lhu

Use MessageBag to store validation errors. Here is an example .

A
Arthur, 2018-10-15
@ART_CORP

@if($errors->has())
   @foreach ($errors->all() as $error)
      <div>{{ $error }}</div>
  @endforeach
@endif

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question