How7oHow7o
  • Home
  • Tools
    • All Tools
    • Image Tools
    • Text & String Tools
    • Video Tools
    • Developer Tools
    • PDF Tools
    • Calculators & More
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Validate a Unique Column on Update in Laravel
Share
Notification Show More
Font ResizerAa
How7oHow7o
Font ResizerAa
  • Tools
  • Prank Screens
  • Learn
  • Blog
Search
  • Home
  • Tools
    • All Tools
    • Image Tools
    • Text & String Tools
    • Video Tools
    • Developer Tools
    • PDF Tools
    • Calculators & More
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Web Development > How to Validate a Unique Column on Update in Laravel
Web Development

How to Validate a Unique Column on Update in Laravel

how7o
By how7o
Last updated: May 23, 2026
4 Min Read
Laravel unique validation that ignores the current record on update
SHARE

To validate a unique column on update in Laravel without rejecting the record’s own current value, add the record’s id as the third argument to the unique rule: unique:vehicles,vehicle_number,$id. The cleaner equivalent is Rule::unique('vehicles')->ignore($vehicle->id), which is the form Laravel’s docs now recommend.

Contents
  • The string-rule form (from the source)
  • The cleaner Rule::unique() form (recommended)
  • Ignore by a non-id column
  • Combine with extra where clauses
  • In a Form Request
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-05-17 on Laravel 11. Originally published 2023-10-11, rewritten and updated 2026-05-17.

The string-rule form (from the source)

// In a controller's update method
$request->validate([
    'vehicle_number' => 'required|max:255|unique:vehicles,vehicle_number,' . $vehicle->id,
]);

The third argument is the id to ignore. The validator runs SELECT … WHERE vehicle_number = ? AND id <> $vehicle->id, so the record’s own current value doesn’t trigger the “already exists” error.

Laravel unique-on-update — string rule with id, Rule::unique()->ignore(), non-id column” class=”wp-image-5771″/></figure>



<h2 id=The cleaner Rule::unique() form (recommended)
use Illuminate\Validation\Rule;

$request->validate([
    'vehicle_number' => [
        'required',
        'max:255',
        Rule::unique('vehicles')->ignore($vehicle->id),
    ],
]);

The Rule facade returns a builder object. ignore($id) is the same idea as the string-rule’s third argument but reads cleanly and handles edge cases (commas in values, special chars) that break string concatenation.

Ignore by a non-id column

Rule::unique('users')->ignore($user->uuid, 'uuid')

For tables that use a UUID or other non-id primary key, pass the column name as the second argument to ignore.

Combine with extra where clauses

// Unique within a single tenant, ignore current record
Rule::unique('vehicles')
    ->where('tenant_id', $tenantId)
    ->ignore($vehicle->id);

// Skip soft-deleted records
Rule::unique('vehicles')
    ->whereNull('deleted_at')
    ->ignore($vehicle->id);

Chain any number of where / whereNull / whereNotNull calls. They become additional WHERE clauses in the uniqueness check.

In a Form Request

// app/Http/Requests/UpdateVehicleRequest.php
public function rules(): array
{
    return [
        'vehicle_number' => [
            'required', 'max:255',
            Rule::unique('vehicles')->ignore($this->route('vehicle')),
        ],
    ];
}

Form Request classes keep validation off the controller. $this->route('vehicle') resolves to the model bound to the route’s {vehicle} parameter (Laravel’s route-model binding), so the id is always the right one for the record being updated.

Frequently asked questions

Why does the unique rule fail on update?

unique:table,column rejects values that already exist in column. On update, the record being edited still has its own value in that column — so the rule sees a match and rejects. The fourth argument $id tells the rule “ignore the row with this primary key” so the record’s own value doesn’t trigger the check.

What’s the difference between the string syntax and Rule::unique()?

Both produce the same SQL. The string form ('unique:vehicles,vehicle_number,'.$id) is concise but breaks subtly when the ignore value contains a comma or pipe. Rule::unique('vehicles')->ignore($id) is explicit, type-safe, and the recommended form in the Laravel docs. Prefer it for new code.

How do I ignore by a non-id column?

Pass both arguments to ignore: Rule::unique('users')->ignore($uuid, 'uuid'). The second argument is the column name to match against. Default is id.

How do I include a soft-deleted record’s value in the uniqueness check?

By default, unique checks every row including soft-deleted ones. To skip soft-deletes: Rule::unique('vehicles')->whereNull('deleted_at')->ignore($id). To skip them only for the current record: ->ignore($id)->whereNull('deleted_at') — order of where* and ignore doesn’t matter for the resulting query.

Related guides

  • How to Check if Exist in the Database with the Laravel Validator
  • How to Validate Input Field to Contain Only Specific Values in Laravel
  • How to Use exists Validation in Laravel Only If the Value Is Not Empty

References

Laravel validation rules — unique: laravel.com/docs/validation#rule-unique. Rule facade: laravel.com/api/master/Illuminate/Validation/Rule.html.

TAGGED:LaravelphpValidation

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Validate an email address in PHP with filter_var How to Validate an Email Address in PHP
Next Article Fix Laravel CSRF token mismatch in DataTables Ajax How to Fix Laravel CSRF Token Mismatch in DataTables Ajax
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

You Might Also Like

MySQL 8 create user and grant privileges on Ubuntu
Web Development

How to Create Users and Grant Privileges in MySQL 8 on Ubuntu

8 Min Read
Laravel Blade Time Format (HH:MM)
Web Development

How to Show Only Hours and Minutes in Laravel Blade (HH:MM)

3 Min Read
Laravel Carbon not found error — namespace import fix
Web Development

Fix “Class Carbon not found” in Laravel

6 Min Read
Get the first character of a PHP string with mb_substr for UTF-8
Web Development

How to Get the First Character of a String in PHP

5 Min Read
How7oHow7o

Free browser-based tools, prank screens, and step-by-step tech tutorials. No signup, nothing uploaded.

  • Private by design — your files never leave your device
  • Instant — no signup, no install, no waiting
  • Always free — no trials, no watermarks, no paywalls

Tools

  • PDF Editor
  • Image Upscaler
  • JPEG Compressor
  • Password Generator
  • QR Code Generator
  • Video Trimmer
  • See all tools →

Pranks

  • Cracked Screen Prank
  • Fake Blue Screen (BSOD)
  • Fake Disk Format
  • Fake Low Battery
  • Fake Nintendo Switch Update Screen
  • Fake PlayStation Update Screen
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?