How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Validate a Unique Column on Update in Laravel
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • 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.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Run Laravel queue workers with Supervisor
How to Run Laravel Queue Workers in Production with Supervisor
May 23, 2026
Nginx as a reverse proxy for a Node.js app on Ubuntu
How to Set Up Nginx as a Reverse Proxy for Node.js on Ubuntu
May 23, 2026
Install and configure Redis on Ubuntu for Laravel and WordPress
How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)
May 23, 2026
Harden a fresh Ubuntu VPS with UFW, Fail2Ban, and SSH key auth
How to Harden a Fresh Ubuntu VPS: UFW + Fail2Ban + SSH Key Auth
May 23, 2026
Set up Let's Encrypt SSL with Certbot on Ubuntu
How to Set Up Let’s Encrypt SSL with Certbot on Ubuntu (Apache & Nginx)
May 23, 2026

You Might Also Like

React.createElement conditional rendering with && short-circuit
Web Development

Conditional Rendering with React.createElement

6 Min Read
How to use localStorage in JavaScript shown in a browser storage panel
Web Development

How to Use localStorage in JavaScript (With Real Examples + Troubleshooting)

8 Min Read
Trigger a function when DataTables loads data via Ajax
Web Development

How to Trigger a Function When DataTables Loads Data

5 Min Read
Laravel unknown column CONCAT fix — DB::raw and selectRaw bypass identifier escaping
Web Development

How to Fix “Unknown column ‘CONCAT'” in Laravel

8 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • 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?