//Controller
$validator = Validator::make($request->all(), [
'name' => 'required|max:255'
],
[
'name.required' => '請輸入名稱!',
]);
if ($validator->fails()) {
return back()->withErrors($validator)->withInput();
}
//blade
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
//api validation
$this->validate($request, [
'is_important' => 'required',
]);