With localhost/api/date/2022-12-12?date=something it will work. Guess why?
Jul 9, 2022
5
Level 3
Validation request in Laravel API
Hi, I have problem with Laravel Request validation in Laravel 9.
I have api.php (route):
Route::get('date/{date}', [HomeController::class, 'date']);
HomeController:
public function date(DateRequest $request, int $date)
{
dd($date);
}
and DateRequest:
class DateRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
return [
'date' => 'required',
];
}
when I open in browser url: localhost/api/date/2022-12-12 - I have redirect to main page.
When I remove from Controller: DateRequest $request or in DataRequest I'm remove 'randomNumber' => 'required',- it's work fine
What's wrong?
Level 75
@trifek Because with validation you don't validate a route parameter...
1 like
Please or to participate in this conversation.