Laravel Between Validation Example

10-Apr-2023

.

Admin

Hi Guys,

In this tutorial i am going to learn you laravel between validation example. We will show how to validate between in laravel application. This tutorial will give you example of between validation example in laravel.

The field under validation must have a size between the given min and max. Strings, numerics, arrays, and files are evaluated in the same fashion as the size rule.

Here i will give solution and full exaple for laravel between validation example So let's see the bellow example.

Solution


$request->validate([

'name' => 'required|between:1,5',

]);

Example

Add Route

Route::get('between',[ValidationController::class,'betweenValidation']);

Route::post('store-between',[ValidationController::class,'betweenStore'])->name('store-between');

Controller : app/Http/Controllers/ValidationController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ValidationController extends Controller

{

public function betweenValidation()

{

return view('validation.betweenValidation');

}

public function betweenStore(Request $request)

{

$request->validate([

'name' => 'required|between:1,5',

]);

}

}

View : resources/views/validation/betweenValidation.blade.php

<!DOCTYPE html>

<html>

<head>

<title>Laravel Between 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" />

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js" integrity="sha512-T/tUfKSV1bihCnd+MxKD0Hm1uBBroVYBOYSk1knyvQ9VyZJpc/ALb4P0r6ubwVPSGB2GvjeoMAJJImBG12TiaQ==" crossorigin="anonymous"></script>

</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 Between Validation Example</strong></h3>

</div>

<div class="card-body">

<form action="{{ route('store-between') }}" method="post">

@csrf

<div class="form-group">

<label>Name :</label>

<input class="form-control" name="name" value="{{ old('name') }}">

@if($errors->has('name'))

<span class="text-danger">{{ $errors->first('name') }}</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>

It will help you....

#Laravel 8

#Laravel 7

#Laravel

#Laravel 6