Skip to content

Conversation

X-Coder264
Copy link
Contributor

This PR aims to improve two things regarding form requests.

  1. In ValidatesWhenResolvedTrait the passes method was called on a \Illuminate\Contracts\Validation\Validator instance even though the passes method doesn't exist on the interface. This was adjusted to call the fails method which is present on the interface and thus I avoided making a breaking change (adding the passes method to the interface).

  2. Unlike the rules and authorize methods, the messages method wasn't called via the container. This was not only inconsistent, but it also meant that I had to write a few more lines than I must now :)

Before this PR:

use Illuminate\Contracts\Translation\Translator;

    public function messages()
    {
        /** @var Translator $translator */
        $translator = $this->container->make(Translator::class);

        return [
            'name.required' => $translator->trans('messages.foobar'),
        ];
    }

After this PR:

use Illuminate\Contracts\Translation\Translator;

    public function messages(Translator $translator)
    {
        return [
            'name.required' => $translator->trans('messages.foobar'),
        ];
    }

I also added a test that proves that method injecting works with the messages method (as well as with rules and authorize methods as that wasn't even tested before).

@seriquynh
Copy link
Contributor

seriquynh commented Aug 9, 2018

You can directly use the Illuminate\Support\Facades\Lang::trans() method or trans() helper.

@taylorotwell
Copy link
Member

Use the __ helper.

@X-Coder264
Copy link
Contributor Author

X-Coder264 commented Aug 9, 2018

@XuanQuynh I actually can't use that. I already explained why in #25038 (comment) Besides, speaking in general - having the framework force me to use facades or some of the global helpers and not giving me the option of some kind of injection (constructor or method) can never be a good thing.

And of all helpers, I especially don't want to use the __ helper as it calls the getFromJson method on a Translator interface instance, but that method isn't present on that interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants