リクエストのバリデーション前に加工したい場合は、
Middleware機能を使うのが良いです。
$ php artisan make:middleware ConvertScoreToIntFilter
app/Http/Middleware/ConvertScoreToIntFilter.php
<?php namespace App\Http\Middleware; use Closure; class ConvertScoreToIntFilter { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $request->merge([ 'score' => (int) str_replace(',', '', $request->score), ]); return $next($request); } }
App/Http/Kernel.php
・・・ protected $routeMiddleware = [ 'auth' => \App\Http\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'admin' => \App\Http\Middleware\Adminpermission::class, 'budgetFileter' => \App\Http\Middleware\ConvertCurrencyToIntFilter::class, ←●追加 ]; ・・・
App/Http/routes.php
Route::post('/scoreInput', 'Admin\ScoreController@create')->middleware('scoreFileter')->name('scoreInput');