블레이드 laravel 에 오류가있는 경우
@if ($errors->any())
@foreach ($errors->all() as $error)
<div>{{$error}}</div>
@endforeach
@endif
라라벨 검증 예제
//import
use Illuminate\Support\Facades\Validator;
// single var check
$validator = Validator::make(['data' => $value],
['data' => 'string|min:1|max:10']
);
if ($validator->fails()) {
// your code
}
// array check
$validator = Validator::make(['data' => $array],
['email' => 'string|min:1|max:10'],
['username' => 'string|min:1|max:10'],
['password' => 'string|min:1|max:10'],
['...' => '...']
);
if ($validator->fails()) {
// your code
}
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
laravel 에서 validater 오류에 사용자 정의 오류를 추가하는 방법
if (request('event') == null) {
$validator->errors()->add('event', 'Please select an event');
}
유효성 검사기 블레이드에서 오류 가져 오기
<!-- /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 -->
라라벨 블레이드보기에서 모든 유효성 검사 오류 표시
@if($errors->has())
@foreach ($errors->all() as $error)
<div>{{ $error }}</div>
@endforeach
@endif