website/vendor/alexgarrett/violin/examples/messages/placeholders/placeholders_all.php

32 lines
614 B
PHP
Raw Normal View History

<?php
/**
* Violin example. Message placeholders.
*
* Shows how you can output all arguments as a comma seperated list,
* if you have a variable amount of arguments for a rule.
*/
require '../../../vendor/autoload.php';
use Violin\Violin;
$v = new Violin;
$v->addRuleMessage('isoneof', '{field} must be one of {$*}');
$v->addRule('isoneof', function($value, $input, $args) {
$value = trim($value);
return in_array($value, $args);
});
$v->validate([
'age' => ['sheep', 'required|isoneof(apples, pears)']
]);
if ($v->passes()) {
// Passed
} else {
var_dump($v->errors()->all());
}