N
N
Nubbb2020-06-29 12:50:20
Laravel
Nubbb, 2020-06-29 12:50:20

How to do validation in laravel?

there is a form for adding information in different languages

​​How to implement validation so that the fields are filled, at least for $language->id = 1

@foreach($languages as $row=>$language)
 <div class="tab-pane fade show @if ($row == 0) active @endif" id="language{{$language->id}}" role="tabpanel">
  <div class="form-group">
    <label for="">ФИО</label>
    <input type="text" class="form-control @error('username') is-invalid @enderror" name="jury_description[{{$language->id}}][username]" required value="@isset($jury) {{$jury->username}} @endisset"> @error('username')
    <span class="invalid-feedback" role="alert">
             <strong>{{ $message }}</strong>
     </span> @enderror
  </div>
</div>
@endforeach


before I decided to make a multilingual site, there was such a validation

public function rules()
    {
        return [
            'username' => ['required', 'string', 'max:255'],
            'description' => ['required', 'string', 'max:255'],
            'image' => ['required', 'string', 'max:255'],
        ];
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-06-29
@Nubbb

You get array validation.
The Laravel documentation has a description of how to validate an array.
For example:

return [
 'jury_description.*.user_name' => 'required|string...'
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question