How to validate decimal digits in laravel

In this tutorial we will discuss how to work laravel decimal validation. How to validate number of digits after decimal space.


Laravel decimal validation rule

Laravel decimal validation rule must contain numeric value and only contain specified number of digits after decimal.

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

use Illuminate\Http\Request;

class ProductController extends Controller
{
  public function store(Request $request) {
    $request->validate([
      'price' => 'decimal:2' // must have two decimal spaces
      'price1' => 'decimal:2,5' // must have 2-5 decimal spaces
    ]);
  }
}
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