app/Rules/StartsWith.php
use Illuminate\Contracts\Validation\Rule; class StartsWith implements Rule{ public function passes($attribute, $value) { return starts_with($value, $this->starts); } public function message() { $str = ''; if (is_array($this->starts)) { $i = 0; foreach ($this->starts as $start) { $str .= ($i !== 0 ? 'or' : null) . ' ' . $start; $i++; } } else { $str = $this->starts; } return 'The :attribute must start with ' . $str; }}