I have got a problem with Laravel.
I have created a custom Form Request - let's call it CustomFormRequest. It is authorized and have got rules as it should be.
In one of the classes I use this request this way:
class CustomClass {
public function __construct(CustomFormRequest $customFormRequest) {
// Code only run from there after a successful validation.
// If there was an error in validation then HTTP 422 error was send by Laravel
}
}
From a Controller, usually I use this CustomClass in this way:
public function Custom(CustomClass $customClass) {
// Code only run from there after a successful validation.
}
But, sometimes, I also try to access this class in this way from either a controller or from other class:
$customRequest = new CustomRequest();
$customRequest->sendMethod('POST');
$customRequest->request->add(...array of data...);
new CustomClass($customRequest);
But it turned out when I use the class this way Laravel somehow skips the validation and even when I gave an invalid data for the class, it will run and tries to put those invalid data into the database!
Is there anything that I missing!? Is another line needed to enforcing the validation!?
Thanks for any further help!
I also tried using $request->validate($request->rules()) but it leads to ERR_TOO_MANY_REDIRECTS.