Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use unique in laravel

Shulou Source: shulou.com Published: 2022-06-02 05:10:52 10月27日 Update

This article mainly shows you "how to use unique in laravel", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to use unique in laravel" this article.

The usage of laravel unique is "'email' = > [' required', 'email',Rule::unique (' customer')->})],", which means that when the update information detects whether the mailbox is duplicated, it excludes itself and all users with a status of 4.

The operating environment of this tutorial: windows7 system, Laravel5.5 version, DELL G3 computer.

Use of Laravel unique rules

The use of unique for laravel:

$customer_type = request ('customer_type', 1) $attributes = request ()-> validate (['gender' = >' required | min:0 | max:3', 'chinese_name' = >' nullable | min:2', 'english_name' = >' nullable | min:3', 'area_phone_number' = >' required | numeric', 'telephone' = >' required | numeric', 'email' = > [' required', 'email' Rule::unique ('customer')-> ignore (request (' id'))-> where (function ($query) {$query- > whereNotIn ('status', [4])) })], / / 'email' = >' required | email | unique:customer,email,'. Request ('id'),' password' = > 'nullable | string | min:6',' concurrent_login_num' = > 'required | min:1 | integer',' child_age' = > 'nullable | integer | min:0',' remark' = > 'nullable | string | max:1024',' status' = > 'required | integer | min:0 | max:4',])

Pay attention to this usage:

'email' = > [' required', 'email', Rule::unique (' customer')-> ignore (request ('id'))-> where (function ($query) {$query- > whereNotIn (' status', [4]);})]

This means that when the update information detects whether the mailbox is duplicated, exclude yourself, and exclude all users with a status of 4. In my case, a user with a status of 4 is deleted. If this mailbox is used by the deleted user, then repeatability is not checked.

Reference: https://laravel.com/docs/5.5/validation file location: d:\ phpStudy\ WWW\ BCCKidAdmin\ vendor\ laravel\ framework\ src\ Illuminate\ Validation\ Rules\ DatabaseRule.php about various verifications: d:\ phpStudy\ WWW\ BCCKidAdmin\ vendor\ laravel\ framework\ src\ Illuminate\ Validation\ Concerns\ ValidatesAttributes.phpD:\ phpStudy\ WWW\ BCCKidAdmin\ vendor\ laravel\\ src\ Illuminate\ Validation\ Concerns\ ReplacesAttributes.php all the contents of the article "how to use unique in laravel" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Status user content article email information learning help update detection location reference materials meaning tutorials files time easy to understand more organization environment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Docker Shulou Tech Info vpn Apple