vovachicago.blogg.se

Eloquent words are not true
Eloquent words are not true






eloquent words are not true

The first approach - use prepareForValidation method

eloquent words are not true

So, how can we handle this?īefore diving in, I want to show you the logic Laravel uses to validate booleans internally, you can actually see that in validateBoolean() method located in Illuminate/Validation/Concerns/ValidatesAttributes. Let’s also say that is_published value coming to us from the client is 'true' or 'false'.Īt this point we already know that validation wouldn’t pass. PostRequest, for simplicity purposes, has a single request input that, first, is required, and second, is boolean, and this input is named is_published. Form requests are custom request classes that encapsulate their own validation and authorization logic. To deeply understand why this is happening, let’s go through an example, let’s say that we have a form request that we call PostRequest. But, that’s not the case, instead, you will be hit with this beautiful error message 'The inputName field must be true or false.'

eloquent words are not true

You would expect, as I did, that this will just work out of the box and Laravel validator will treat them as boolean. This post was originally published on my personal blog on 30th December 2021.Įvery once in a while you come across a situation where you need to validate a request input as a boolean, and the input value is 'true' or 'false' (notice that I wrapped the values inside single quotes to indicate that those are actually strings).








Eloquent words are not true