You can include or exclude fields from the validated array by using the not()
, only()
and pluck()
methods:
use KrisKuiper\Validator\Validator;
$data = [
'username' => 'Morris',
'email' => '[email protected]',
'password' => '123',
'interest' => [
['title' => 'programming'],
['title' => 'coding']
]
];
$validator = new Validator($data);
$validator
->field('username', 'email', 'password', 'interest.*.title')
->required();
$validator->execute();
Include field names using only()
method:
$validator
->validatedData()
->only('username', 'email')
->toArray();
This will return:
array(
'username' => 'Morris',
'email' => '[email protected]'
);
Exclude field names using not()
method:
$validator
->validatedData()
->not('username', 'email', 'interest')
->toArray();
This will return:
array('password' => '123');
Extract multiple columns in key-pair value using pluck()
method:
$validator
->validatedData()
->pluck('interest.*.title')
->toArray();
This will return:
array('programming', 'coding');
Go to the previous section.
Go to the next section.