I currently have a few validation rules as follows:
\Route::post("/logError", "LogController@logError");
//In LogController
public function logError(Request $request) {
$rules = [
"name" => "required",
"message" => "required",
"level" => "in:info,debug,error"
];
$this->validate($request,$rules);
// Log the message or do whatever
});
This works fine for inputs like
[ "name"=>"Not found", "message" => "Element not found", "level" => "error" ]
[ "name"=>"Not found", "message" => "Element not found" ]`
However it throws an exception for inputs like
[ "name"=>"Not found", "message" => "Element not found", "level" => "randomgibberish" ]
My question is, since "level" is optional, is there a built-in way to validate the input and just remove optional elements that are not valid from it instead of throwing a validation exception? If not would I have to override the controller validation method to achieve this?
filter_varin PHP can do both). I'll try to untangle them from my head (and then my code).