['required', 'email',Rule::unique('customer')->...})]," which means that when updating information to detect whether the mailbox is duplicated, exclude self and exclude all users with status 4."/> ['required', 'email',Rule::unique('customer')->...})]," which means that when updating information to detect whether the mailbox is duplicated, exclude self and exclude all users with status 4.">
search
HomePHP FrameworkLaravelWhat is the usage of laravel unique

What is the usage of laravel unique

Dec 27, 2021 pm 02:39 PM
laravelunique

The usage of laravel unique is "'email' => ['required', 'email',Rule::unique('customer')->...})]," which means update When checking whether the mailbox is duplicated, exclude yourself and all users with status 4.

What is the usage of laravel unique

The operating environment of this tutorial: Windows 7 system, Laravel version 5.5, DELL G3 computer.

Laravel unique rule usage

Laravel’s unique usage:

      $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 When updating information to detect whether mailboxes are duplicated, exclude yourself and all users with status 4. In my case, users with status 4 are deleted. If this mailbox is used by a deleted user, then the duplication is not checked.

参考资料:https://laravel.com/docs/5.5/validation
文件位置:
D:\phpStudy\WWW\BCCKidAdmin\vendor\laravel\framework\src\Illuminate\Validation\Rules\DatabaseRule.php
关于各种的的验证:
D:\phpStudy\WWW\BCCKidAdmin\vendor\laravel\framework\src\Illuminate\Validation\Concerns\ValidatesAttributes.php
D:\phpStudy\WWW\BCCKidAdmin\vendor\laravel\framework\src\Illuminate\Validation\Concerns\ReplacesAttributes.php

Related recommendations: The latest five Laravel video tutorials

The above is the detailed content of What is the usage of laravel unique. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Last Laravel version: Migration TutorialLast Laravel version: Migration TutorialMay 14, 2025 am 12:17 AM

What new features and best practices does Laravel's migration system offer in the latest version? 1. Added nullableMorphs() for polymorphic relationships. 2. The after() method is introduced to specify the column order. 3. Emphasize handling of foreign key constraints to avoid orphaned records. 4. It is recommended to optimize performance, such as adding indexes appropriately. 5. Advocate the idempotence of migration and the use of descriptive names.

What is the Latest LTS Version of Laravel?What is the Latest LTS Version of Laravel?May 14, 2025 am 12:14 AM

Laravel10,releasedinFebruary2023,isthelatestLTSversion,supportedforthreeyears.ItrequiresPHP8.1 ,enhancesLaravelPennantforfeatureflags,improveserrorhandling,refinesdocumentation,andoptimizesperformance,particularlyinEloquentORM.

Stay Updated: The Newest Features in the Latest Laravel VersionStay Updated: The Newest Features in the Latest Laravel VersionMay 14, 2025 am 12:10 AM

Laravel's latest version introduces multiple new features: 1. LaravelPennant is used to manage function flags, allowing new features to be released in stages; 2. LaravelReverb simplifies the implementation of real-time functions, such as real-time comments; 3. LaravelVite accelerates the front-end construction process; 4. The new model factory system enhances the creation of test data; 5. Improves the error handling mechanism and provides more flexible error page customization options.

Implementing Soft Delete in Laravel: A Step-by-Step TutorialImplementing Soft Delete in Laravel: A Step-by-Step TutorialMay 14, 2025 am 12:02 AM

Softleteinelelavelisling -Memptry-braceChortsDevetus -TeedeecetovedinglyDeveledTeecetteecedelave

Current Laravel Version: Check the Latest Release and UpdatesCurrent Laravel Version: Check the Latest Release and UpdatesMay 14, 2025 am 12:01 AM

Laravel10.xisthecurrentversion,offeringnewfeatureslikeenumsupportinEloquentmodelsandimprovedroutemodelbindingwithenums.Theseupdatesenhancecodereadabilityandsecurity,butrequirecarefulplanningandincrementalimplementationforasuccessfulupgrade.

How to Use Laravel Migrations: A Step-by-Step TutorialHow to Use Laravel Migrations: A Step-by-Step TutorialMay 13, 2025 am 12:15 AM

LaravelmigrationsstreamlinedatabasemanagementbyallowingschemachangestobedefinedinPHPcode,whichcanbeversion-controlledandshared.Here'showtousethem:1)Createmigrationclassestodefineoperationslikecreatingormodifyingtables.2)Usethe'phpartisanmigrate'comma

Finding the Latest Laravel Version: A Quick and Easy GuideFinding the Latest Laravel Version: A Quick and Easy GuideMay 13, 2025 am 12:13 AM

To find the latest version of Laravel, you can visit the official website laravel.com and click the "Docs" button in the upper right corner, or use the Composer command "composershowlaravel/framework|grepversions". Staying updated can help improve project security and performance, but the impact on existing projects needs to be considered.

Staying Updated with Laravel: Benefits of Using the Latest VersionStaying Updated with Laravel: Benefits of Using the Latest VersionMay 13, 2025 am 12:08 AM

YoushouldupdatetothelatestLaravelversionforperformanceimprovements,enhancedsecurity,newfeatures,bettercommunitysupport,andlong-termmaintenance.1)Performance:Laravel9'sEloquentORMoptimizationsenhanceapplicationspeed.2)Security:Laravel8introducedbetter

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools