laravel / ideas

Issues board used for Laravel internals discussions.
939 stars 28 forks source link

[Proposal] Validation Exception Factory #1558

Open joelharkes opened 5 years ago

joelharkes commented 5 years ago

I maybe too quickly made a PR for this (see: https://github.com/laravel/framework/pull/27833/files). Let me explain the proposal.

Problem

Current issues with validation (Exception):

Solution

The factory method (+interface/contract for it) for the exception is feasible because everywhere the exception is thrown there is aso the IOC container that can be used to instantiate this factory.

Users of laravel framework can than extend the ValidationExceptionFactory to inject a translation for the ValidationException and can overwrite the methods to return a sublcass of ValidationException to provide additional formatting of the http response returned to the client.

joelharkes commented 5 years ago

I build a pr: it gets rejected telling me I should go here. I go here, nothing happens?

ollieread commented 5 years ago

There are a lot of ways to control this, primarily, by overriding Illuminate\Foundation\Exceptions::invalidJson(). A factory for validation exceptions isn't really the solution to this problem.