Im trying to send a email with a list of companies that have the pending or waiting status.
This list is already collected in the following function:
public static function getCompaniesAwaitingCheck()
{
$awaitingChangeApproval = self::getAwaitingChangeApproval();
$awaitingPublication = self::getAwatingPublication();
return array_merge($awaitingChangeApproval, $awaitingPublication);
}
Now I want to use that function to put in the email. I have made a separate class for this (AdminPendingApprovalNotification.php
)
In there is the following function:
public function notifyPendingApproval()
{
$dailyClaimMailTitle = get_field("daily_claim_overview_mail_title", 'options');
$dailyClaimMailText = get_field('daily_claim_overview_mail_text', 'options');
$dailyClaimMailAddress = get_field('daily_claim_overview_mail', 'options');
$company = new Company();
$pendingCompany = $company->getCompaniesAwaitingCheck();
wp_mail(
$dailyClaimMailAddress,
ecs_get_template_part('views/email/template', [
'title' => $dailyClaimMailTitle,
'text' => $dailyClaimMailText, $pendingCompany,
], false),
['Content-Type: text/html; charset=UTF-8']
);
}
When I dd($pendingCompany);
I get the error:PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function Models\Model::__construct(), 0 passed in Emails/AdminPendingApprovalNotification.php on line 16 and exactly 1 expected
line 16: $company = new Company();
Unfortunately can’t get it to work, I’m a beginner, some help would be appreciated. Thanks!
CodePudding user response:
Your method getCompaniesAwaitingCheck
is static, so you should call it like:
$pendingCompany = Company::getCompaniesAwaitingCheck();
An error occured because your Company
class requires arguments in the __construct
method, which you didn't provide.