我在Laravel 5.4中有这个方法:
/**
* Check if domain is valid
*
* @param string $emails
* @param string $domain
* @return bool
*/
public function isValidDomain(string $emails, string $domain)
{
collect(explode(',', $emails))->each(function($email) use ($domain) {
return $this->containsAtSymbol($email) && $this->getDomain($email) == $domain;
});
}
在这里,我检查来自电子邮件地址的域名是否有效。那么我怎么能说当其中一个是真的时候,那么返回true:
return $this->containsAtSymbol($email) && $this->getDomain($email) == $domain;
答案 0 :(得分:1)
使用方法contains,如下所示:
$result = collect(explode(',', $emails))->contains(function($email) use ($domain) {
return $this->containsAtSymbol($email) && $this->getDomain($email) == $domain;
});
$result
值为true
或false