本文整理汇总了PHP中Carbon::yesterday方法的典型用法代码示例。如果您正苦于以下问题:PHP Carbon::yesterday方法的具体用法?PHP Carbon::yesterday怎么用?PHP Carbon::yesterday使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Carbon
的用法示例。
在下文中一共展示了Carbon::yesterday方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: function
<?php
/**
* Created by PhpStorm.
* User: veoc
* Date: 30/10/16
* Time: 11:26 AM
*/
$factory->define(\App\Modules\SaleModule\Entities\Sale::class, function (\Faker\Generator $faker) {
return ['price' => 0.01, 'start' => Carbon::yesterday(), 'end' => Carbon::today()->addDays($faker->randomNumber(1))];
});
示例2: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
// get all the users
$users = User::all();
$previousDayDate = Carbon::yesterday()->toDateString();
// currently calculated metrics
$currentMetrics = Calculator::currentMetrics();
// for each user send email with their metrics
$dailyEmailSent = 0;
$weeklyEmailSent = 0;
foreach ($users as $user) {
// check if user finished the connect process
if ($user->isConnected() && $user->ready == 'connected' && !$user->isTrialEnded()) {
switch ($user->summaryEmailFrequency) {
case 'none':
// no summary email
break;
case 'daily':
// default behavior, send yesterday's data
// get the user's metrics
$metric = Metric::where('user', $user->id)->where('date', $previousDayDate)->first();
if ($metric) {
$previousMetrics = Metric::where('user', $user->id)->where('date', '<=', Carbon::yesterday()->subDays(30)->toDateString())->orderBy('date', 'desc')->first();
$changes = array();
foreach ($currentMetrics as $metricID => $metricDetails) {
// get the correct color
$changes[$metricID]['positiveIsGood'] = $metricDetails['metricClass']::POSITIVE_IS_GOOD;
$date = $metric->date;
if ($previousMetrics) {
if ($previousMetrics->{$metricID} != 0) {
$value = $metric->{$metricID} / $previousMetrics->{$metricID} * 100 - 100;
$changes[$metricID][$date]['isBigger'] = $value > 0 ? true : false;
$changes[$metricID][$date]['value'] = round($value) . ' %';
} else {
$changes[$metricID][$date]['value'] = null;
}
} else {
$changes[$metricID][$date]['value'] = null;
}
}
// format metrics to presentable data
$metric->formatMetrics();
// this line is for making the daily email the same format as the weekly
// so we only need one email template
$metrics = array($metric->date => $metric);
$data = array('metrics' => $metrics, 'currentMetrics' => $currentMetrics, 'changes' => $changes, 'isDaily' => true, 'index' => 0);
$email = Mailman::make('emails.summary')->with($data)->to($user->email)->subject('Daily summary')->send();
//File::put(public_path().'/summary_email.html',$email);
$dailyEmailSent++;
}
break;
case 'weekly':
// send a weekly summary to the user with their numbers
// check if today is monday (we send weekly emails on monday)
/* improvment idea
change this if to switch-case with days
for user controlled daily send
*/
if (Carbon::now()->dayOfWeek == Carbon::WEDNESDAY) {
// get the user's metrics
$metrics = Metric::where('user', $user->id)->where('date', '<=', $previousDayDate)->orderBy('date', 'desc')->take(7)->get();
$previousMetrics = Metric::where('user', $user->id)->where('date', '<=', Carbon::yesterday()->subDays(30)->toDateString())->orderBy('date', 'desc')->take(7)->get();
$changes = array();
foreach ($currentMetrics as $metricID => $metricDetails) {
// get the correct color
$changes[$metricID]['positiveIsGood'] = $metricDetails['metricClass']::POSITIVE_IS_GOOD;
foreach ($previousMetrics as $id => $prevMetric) {
$date = $metrics[$id]->date;
if ($prevMetric->{$metricID} != 0) {
$value = $metrics[$id]->{$metricID} / $prevMetric->{$metricID} * 100 - 100;
$changes[$metricID][$date]['isBigger'] = $value > 0 ? true : false;
$changes[$metricID][$date]['value'] = round($value) . ' %';
} else {
$changes[$metricID][$date]['value'] = null;
}
}
}
// format metrics to presentable data
$weeklyMetrics = array();
foreach ($metrics as $metric) {
$metric->formatMetrics();
$weeklyMetrics[$metric->date] = $metric;
}
$data = array('metrics' => $weeklyMetrics, 'currentMetrics' => $currentMetrics, 'changes' => $changes, 'isDaily' => false, 'index' => 0);
// login the user (necessary to get the email address)
// Auth::login($user);
// send the email to the user
$email = Mailman::make('emails.summary')->with($data)->to($user->email)->subject('Weekly summary')->send();
//File::put(public_path().'/summary_email.html',$email);
$weeklyEmailSent++;
}
break;
default:
Log::error('notifications string has been changed, check the email sending code');
break;
//.........这里部分代码省略.........