Answers for "show validation error in laravel 8"

PHP
4

how to show validation error in laravel blade

@if($errors->any())
    <div class="alert alert-danger">
        <p><strong>Opps Something went wrong</strong></p>
        <ul>
        @foreach ($errors->all() as $error)
            <li>{{ $error }}</li>
        @endforeach
        </ul>
    </div>
@endif

@if(session('success'))
    <div class="alert alert-success">{{session('success')}}</div>
@endif

@if(session('error'))
    <div class="alert alert-danger">{{session('error')}}</div>
@endif
Posted by: Guest on October-29-2020
7

laravel validation display errors

public function store(Request $request)
{
    $validator = Validator::make($request->all(), [
        'title' => 'bail|required|max:255',
        'body' => 'required',
    ]);

    // Check validation failure
    if ($validator->fails()) {
       // [...]
      
      foreach($validator->messages()->getMessages() as $field_name => $messages) {

                // Go through each message for this field.
                foreach($messages AS $message) {
                    echo '***********'.$message.'***********<br>';
                }
            }
    }

    // Check validation success
    if ($validator->passes()) {
       // [...]
    }

    // Retrieve errors message bag
    $errors = $validator->errors();
}
Posted by: Guest on June-29-2021

Code answers related to "show validation error in laravel 8"

Browse Popular Code Answers by Language