Required_if with data type - Laravel

103
July 11, 2018, at 11:20 PM

I want to validate name & status.

If status = 1 else it should skip validation of name. When I send status = 0 it says:

name must be a string

But it should skip validation of name as per conditional validation.

When I send status=1 then it works as intended.

'status' => 'required|numeric',
'name' => 'required_if:status,1|string'

What needs to be corrected here?

Answer 1

You do resolve this:

public function rules()
{
   $rules = [
       'status' => ['required', 'numeric'],
       'name' => ['string'],
   ];
   if ($this->status == '1') {
       array_push($rules['name'], 'required');
   }
   return $rules;
}
READ ALSO
Typo3 - Save GET-Value to Session

Typo3 - Save GET-Value to Session

Im currently developing a extension for Typo3 87 and want to store a GET-Parameter in the session of the frontend user

68
Using strpos to locate a particular substring and store the following (PHP)

Using strpos to locate a particular substring and store the following (PHP)

I have the values of a Database query stored in a $domainsEach record looks like so: domain_23, domain_88, domain_0 etc

62
Update grandchild repeater field with value per row

Update grandchild repeater field with value per row

I'm trying to take the following data from a table:

73
Como fazer efeito água fotos (How to make water effect on photos) [on hold]

Como fazer efeito água fotos (How to make water effect on photos) [on hold]

Ola, gostaria de ajuda para fazer esse efeito usando PHP GD ou PHP & ImageMagick

71