1<!-- /resources/views/post/create.blade.php -->
2
3<h1>Create Post</h1>
4
5@if ($errors->any())
6 <div class="alert alert-danger">
7 <ul>
8 @foreach ($errors->all() as $error)
9 <li>{{ $error }}</li>
10 @endforeach
11 </ul>
12 </div>
13@endif
14
15<!-- Create Post Form -->
1/**
2 * Store a new blog post.
3 *
4 * @param Request $request
5 * @return Response
6 */
7public function store(Request $request)
8{
9 $validatedData = $request->validate([
10 'title' => 'required|unique:posts|max:255',
11 'body' => 'required',
12 ]);
13
14 // The blog post is valid...
15}
1<?php
2
3namespace App\Providers;
4
5use Illuminate\Support\ServiceProvider;
6use Illuminate\Support\Facades\Validator;
7
8class AppServiceProvider extends ServiceProvider
9{
10 /**
11 * Register any application services.
12 *
13 * @return void
14 */
15 public function register()
16 {
17 //
18 }
19
20 /**
21 * Bootstrap any application services.
22 *
23 * @return void
24 */
25 public function boot()
26 {
27 Validator::extend('foo', function ($attribute, $value, $parameters, $validator) {
28 return $value == 'foo';
29 });
30 }
31}
1use Illuminate\Validation\Rule;
2
3Validator::make($data, [
4 'email' => [
5 'required',
6 Rule::unique('users')->ignore($user->id),
7 ],
8]);
1"foo" => "Your input was invalid!",
2
3"accepted" => "The :attribute must be accepted.",
4
5// The rest of the validation error messages...
1Validator::extendImplicit('foo', function ($attribute, $value, $parameters, $validator) {
2 return $value == 'foo';
3});
1$rules = ['name' => 'unique:users,name'];
2
3$input = ['name' => ''];
4
5Validator::make($input, $rules)->passes(); // true