Answer the question
In order to leave comments, you need to log in
How to validate data in API?
It is necessary to validate the data and the fields themselves in the API, I tried to use FormRequest, after that I receive this object in the controller method. sample code:
class GetReqData extends FormRequest implements InterfaceGetTripsListRequest
{
public function authorize()
{
return true;
}
public function validate()
{
return [
'user_id' => 'required|integer'
];
}
public function getUserId():int
{
return (int)$this->get('user_id');
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question