Laravel validates two fields values must be different

In this tutorial we will discuss Laravel different validation rule. How to validate two fields value became different in laravel.


Laravel different values validation

When you want one field value different to another field than use different validation rule.

App/Http/Controllers/UserController.php
<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;

class UserController extends Controller
{
  public function store(Request $request) {
    $request->validate([
      'name' => 'required|different:password',
      'password' => 'required|different:name'
    ]);
  }
}

In our example name and password field values not became exact same.

php laravel developer anmol sharma

Anmol Sharma

I am a software engineer and have experience in web development technologies like php, Laravel, Codeigniter, javascript, jquery, bootstrap and I like to share my deep knowledge by these blogs.

Random tutorial links