I have a GET route with wildcard Date.
The day wildcard is a string as follows: 20220507 (YYYYMMDD).
After validating the string I want a correct response. Before sending the response I want to verify the string length and format.
My question is, is it possible to validate the string using Illuminate\Foundation\Http\FormRequest or Illuminate\Http\Request Production: Request? Or do they only accept publishing requests?
Code:
php artisan make:request CalendarDayRequest
Example of getting routes in web.php
Route::get('/calendar/{day}' , 'App\Http\Controllers\HomeController@calendar')->name('calendar');
Sample Controller
use App\Http\Requests\CalendarDayRequest; public function calendar ( CalendarDayRequest $request ) { // Code }
Or sample controller 2
use Illuminate\Http\Request; public function calendar ( Request $request ) { $validated = $request->validate([ 'day' => 'required', ]); }
I'm getting the error: Infinite redirect loop, too many redirects.
First, you cannot validate route parameters in form requests
However, you can use regular expressions to validate your routes Example:
If you still want to use
validate()
function or form requestForm request method - override
all()
methodIf that doesn't work, try the following code
How to verify routing parameters in Laravel 5?
But if you want to use the
validate()
function, I recommend you send it as a request parameter.