1/**
2 * Store a new blog post.
3 *
4 * @param Request $request
5 * @return Response
6 */
7
8public function store(Request $request)
9{
10 $validatedData = $request->validate([
11 'title' => 'required|unique:posts|max:255',
12 'body' => 'required',
13 ]);
14
15 // The blog post is valid...
16}
1$rules = [
2 'name' => 'required',
3 'email' => 'required|email',
4 'message' => 'required|max:250',
5 ];
6
7 $customMessages = [
8 'required' => 'The :attribute field is required.'
9 ];
10
11 $this->validate($request, $rules, $customMessages);
1use Illuminate\Validation\Rule;
2
3public function rules()
4{
5 return [
6 'title' => [
7 'required',
8 Rule::unique('posts', 'title')->ignore($this->post)
9 ]
10 ];
11}
12
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}
1unique:table,column,except,idColumn
2
3############## Example : ################
4
5############### For Updating
6//rules
7'email' => 'unique:users,email_address,' . $userId,
8
9############### For Creating
10//rules
11'email' => 'unique:users,email_address',
1# <values> = foo,bar,...
2# <field> = array field
3# <characters> = amount of characters
4
5# accepted # active_url
6# after:<tomorrow> # after_or_equal:<tomorrow>
7# alpha # alpha_dash
8# alpha_num # array
9# bail # before:<today>
10# before_or_equal:<today> # between:min,max
11# boolean # confirmed
12# date # date_equals:<today>
13# date_format:<format> # different:<name>
14# digits:<value> # digits_between:min,max
15# dimensions:<min/max_with> # distinct
16# email # ends_with:<values>
17# exclude_if:<field>,<value> # exclude_unless:<field>,<value>
18# exists:<table>,<column> # file
19# filled # gt:<field>
20# gte:<field> # image
21# in:<values> # in_array:<field>
22# integer # ip
23# ipv4 # ipv6
24# json # lt:<field>
25# lte:<field> # max:<value>
26# mimetypes:video/avi,... # mimes:jpeg,bmp,png
27# min:<value> # not_in:<values>
28# not_regex:<pattern> # nullable
29# numeric # password:<auth guard>
30# present # regex:<pattern>
31# required # required_if:<field>,<value>
32# required_unless:<field>,<value> # required_with:<fields>
33# required_with_all:<fields> # required_without:<fields>
34# required_without_all:<fields> # same:<field>
35# size:<characters> # starts_with:<values>
36# string # timezone
37# unique:<table>,<column> # url
38# uuid