forked from eatvio/eatvio-infra
27 lines
534 B
PHP
27 lines
534 B
PHP
<?php
|
|
|
|
namespace App\Rules;
|
|
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
|
|
class MinWords implements Rule
|
|
{
|
|
protected $minWords;
|
|
|
|
public function __construct($minWords)
|
|
{
|
|
$this->minWords = $minWords;
|
|
}
|
|
|
|
public function passes($attribute, $value)
|
|
{
|
|
$wordCount = count(preg_split('/\W+/u', $value, -1, PREG_SPLIT_NO_EMPTY));
|
|
return $wordCount >= $this->minWords;
|
|
}
|
|
|
|
public function message()
|
|
{
|
|
return "The :attribute must have at least {$this->minWords} words.";
|
|
}
|
|
}
|