Spatie\Newsletter\NewsletterListCollection::findByName PHP Method

findByName() public method

public findByName ( string $name ) : NewsletterList
$name string
return NewsletterList
    public function findByName($name)
    {
        if ((string) $name === '') {
            return $this->getDefault();
        }
        foreach ($this->items as $newsletterList) {
            if ($newsletterList->getName() === $name) {
                return $newsletterList;
            }
        }
        throw InvalidNewsletterList::noListWithName($name);
    }

Usage Example

Example #1
0
 /**
  * @param string $fromName
  * @param string $replyTo
  * @param string $subject
  * @param string $html
  * @param string $listName
  * @param array  $options
  * @param array  $contentOptions
  *
  * @return array|bool
  *
  * @throws \Spatie\Newsletter\Exceptions\InvalidNewsletterList
  */
 public function createCampaign($fromName, $replyTo, $subject, $html = '', $listName = '', $options = [], $contentOptions = [])
 {
     $list = $this->lists->findByName($listName);
     $defaultOptions = ['type' => 'regular', 'recipients' => ['list_id' => $list->getId()], 'settings' => ['subject_line' => $subject, 'from_name' => $fromName, 'reply_to' => $replyTo]];
     $options = array_merge($defaultOptions, $options);
     $response = $this->mailChimp->post('campaigns', $options);
     if (!$this->lastActionSucceeded()) {
         return false;
     }
     if ($html === '') {
         return $response;
     }
     if (!$this->updateContent($response['id'], $html, $contentOptions)) {
         return false;
     }
     return $response;
 }