Today now in this blog,I will explain you how to validation only numeric in laravel application. we can easy to use validation number in laravel application . Here we are show the laravel numeric validation. So now here we will field under validation that’s allow only numbers in laravel application.
So in this example,we can simply apply to validation to Numeric Validation in laravel application. Now the field under validation so must have a numeric value.
So now here the example of laravel validation allow only numbers.
So let’s start and see below the solution
solution
$request->validate([ "playerName" => "required", "score" => "required|numeric" ]);
Route : routes/web.php
Route::get('blogs','BlogController@index'); Route::post('blogs','BlogController@store')->name('blogs.store');
Controller : app/Http/Controllers/BlogController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Notifications\Notification; class BlogController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { return view('index'); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $request->validate([ "playerName" => "required", "score" => "required|numeric" ]); return redirect()->back(); } }
View : resources/views/index.php
I hope it will help you. Also you can follow us on Facebook