Hello Devs, 

In this tutorial, we will learn the Laravel Validation lte field Example

The field under validation must be less than or equal to the given field. The two fields must be of the same type.

Follow this step-by-step guide. 

Solution :

$request->validate([
    'amount' => 'required|lte:100',
]);


Full Example:

Add Route

use App\Http\Controllers\ValidationController;

Route::get('lte',[ValidationController::class,'lteValidation']);
Route::post('store-lte',[ValidationController::class,'lteStore'])->name('store-lte');


Controller : app/Http/Controllers/ValidationController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ValidationController extends Controller
{
    public function lteValidation()
    {
        return view('validation.lteValidation');
    }

    public function lteStore(Request $request)
    {
        $request->validate([
            'amount' => 'required',
            'adv_amount' => 'required|lte:amount',
        ]);
    }
}


View : resources/views/validation/lteValidation.php

<!DOCTYPE html>
<html>
<head>
    <title>Laravel lte Validation Example</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.3/css/bootstrap.min.css" integrity="sha512-oc9+XSs1H243/FRN9Rw62Fn8EtxjEYWHXRvjS43YtueEewbS6ObfXcJNyohjHqVKFPoXXUxwc+q1K7Dee6vv9g==" crossorigin="anonymous" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.3/js/bootstrap.min.js" integrity="sha512-8qmis31OQi6hIRgvkht0s6mCOittjMa9GMqtK9hes5iEQBQE/Ca6yGE5FsW36vyipGoWQswBj/QBm2JR086Rkw==" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css" integrity="sha512-mSYUmp1HYZDFaVKK//63EcZq4iFWFjxSL+Z3T/aCt4IO9Cejm03q3NKKYN6pFQzY0SBOr8h+eCIAZHPXcpZaNw==" crossorigin="anonymous" />
</head>
<body>
    <div class="container mt-5">
        <div class="row">
            <div class="col-md-8 offset-2 mt-5">
                <div class="card">
                    <div class="card-header bg-info text-white">
                        <h3><strong>Laravel lte Validation Example</strong></h3>
                    </div>
                    <div class="card-body">
                        <form action="{{ route('store-lte') }}" method="post">
                            @csrf
                            <div class="form-group">
                                <label>Amount :</label>
                                <input class="form-control" name="amount" value="{{ old('amount') }}">
                                @if($errors->has('amount'))
                                    <span class="text-danger">{{ $errors->first('amount') }}</span>
                                @endif
                            </div>
                            <div class="form-group">
                                <label>Adv. Amount :</label>
                                <input class="form-control" name="adv_amount" value="{{ old('amount') }}">
                                @if($errors->has('adv_amount'))
                                    <span class="text-danger">{{ $errors->first('adv_amount') }}</span>
                                @endif
                            </div>
                            <div class="form-group">
                                <button class="btn btn-success btn-sm">Save</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>


Run Your Project:

php artisan serve

open bellow URL on your browser:

http://localhost:8000/lte


May this example help you.