简体   繁体   English

Laravel集合返回值

[英]Laravel collection return value

I've got this method in Laravel 5.4: 我在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;
        });
    }

Here I check if the domain from an email adres is valid. 在这里,我检查来自电子邮件地址的域是否有效。 So how could I say that when one of them is true, then return true: 所以我怎么能说当其中之一为真时,然后返回真:

return $this->containsAtSymbol($email) && $this->getDomain($email) == $domain;

Use method contains like this: 使用方法包含如下内容:

$result = collect(explode(',', $emails))->contains(function($email) use ($domain) {
   return $this->containsAtSymbol($email) && $this->getDomain($email) == $domain;
});

And the $result value will be true or false $result值将为truefalse

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM