Answers for "how to display * with requred field validation in laravel"

PHP
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
2

laravel validation show

<!-- /resources/views/post/create.blade.php -->

<h1>Create Post</h1>

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

<!-- Create Post Form -->
Posted by: Guest on August-22-2020

Code answers related to "how to display * with requred field validation in laravel"

Browse Popular Code Answers by Language