display errors in laravel code example
Example 1: laravel get errors from validator blade
<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
Example 2: displaying errors in laravel
@if(count($errors) > 0)
<div class="p-1">
@foreach($errors->all() as $error)
<div class="alert alert-warning alert-danger fade show" role="alert">{{$error}} <button type="button" class="close"
data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button></div>
@endforeach
</div>
@endif
Example 3: $errors show this error in laravel
<input type="text" name="firstname">
@if($errors->has('firstname'))
<div class="error">{{ $errors->first('firstname') }}</div>
@endif