Open BadChoice opened 9 years ago
I can't speak for @JeffreyWay, but L5 offers form request validation which can simplify the process immensely.
Yea, form request validation looks great, but what if you are not using a form? Or even, you need to have another class for each model with its request validation, which means lots of more code
Or is there an easiest way?
It would depend on your specific use case....
In my use case I need model validation as I am building an API.
Looking at the FormRequest
class's response()
method:
public function response(array $errors)
{
if ($this->ajax() || $this->wantsJson())
{
return new JsonResponse($errors, 422);
}
return $this->redirector->to($this->getRedirectUrl())
->withInput($this->except($this->dontFlash))
->withErrors($errors, $this->errorBag);
}
This leads me to believe they should work with API requests just fine, although I don't have time to check this at the minute.
Is there planned an update for L5 compatibility?