/**
  * Create a unique token
  *
  * @return mixed
  */
 public function createUniqueToken()
 {
     $token = $this->model->createToken();
     if ($this->model->isTokenUnique($token)) {
         return $token;
     }
     $this->createToken();
 }
 /**
  * Unsubscribe from a LaSalleCRM email list
  *
  * @param $token
  */
 public function unsubscribe($token)
 {
     // Does the token exist in the list_unsubscribe_token database table?
     if (!$this->model->isTokenValid($token)) {
         return view('lasallecrmlistmanagement::subscribe-unsubscribe-list.token_invalid', ['title' => 'Invalid Unsubscribe Token']);
     }
     $emailID = $this->model->getEmailIdByToken($token);
     $listID = $this->model->getListIdByToken($token);
     // email address
     $email = $this->emailRepository->getEmailByEmailId($emailID);
     // list's name
     $listName = $this->listRepository->getListnameByListId($listID);
     // Delete all list_unsubscribe_token records for this email_id and list_id
     $this->model->deleteAllTokensForListIDandEmailID($listID, $emailID);
     // un-enabled (ie, disable) the list_email database record for this email_id and list_id
     $this->list_EmailRepository->enabledFalse($emailID, $listID);
     return view('lasallecrmlistmanagement::subscribe-unsubscribe-list.unsubscribe_success', ['title' => 'Unsubscribe Successful', 'email' => $email, 'listName' => $listName]);
 }
 /**
  * Get list ID by token
  *
  * @param  text  $token
  * @return mixed
  */
 public function getListIdByToken($token)
 {
     $unsubscribe = List_Unsubscribe_Token::where('token', $token)->first();
     return $unsubscribe->list_id;
 }