本文整理汇总了PHP中Carbon\Carbon::now方法的典型用法代码示例。如果您正苦于以下问题:PHP Carbon::now方法的具体用法?PHP Carbon::now怎么用?PHP Carbon::now使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Carbon\Carbon
的用法示例。
在下文中一共展示了Carbon::now方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildNextWeekTag
/**
* 金曜日になると今週の週報タグを生成する
*/
public function buildNextWeekTag()
{
\Log::info('Start generate tag of This week. ');
$dt = new Carbon();
// $dt->setTestNow($dt->createFromDate(2015, 5, 31));
if ($dt->now()->dayOfWeek === Carbon::FRIDAY) {
//翌月
$nextMonth = $dt->parse('next month')->month;
// 現在が何週目か
\Log::info('今日は' . $dt->now()->month . '月の第' . $dt->now()->weekOfMonth . '週目です');
//今週の金曜を取得
$thisFriday = $dt->parse('this friday');
\Log::info('来週の金曜は' . $thisFriday);
// 月またぎの場合
if ($thisFriday->month === $nextMonth) {
\Log::info($thisFriday->year . '年の' . $thisFriday->month . '月の第' . $thisFriday->weekOfMonth . '週目です');
$nextWeekTag = '週報@' . $thisFriday->year . '年' . $thisFriday->month . '月第' . $thisFriday->weekOfMonth . '週';
$this->tag->tag = $nextWeekTag;
$this->tag->save();
} else {
\Log::info('翌週は' . $thisFriday->month . '月の第' . $thisFriday->weekOfMonth . '週目です');
$nextWeekTag = '週報@' . $thisFriday->year . '年' . $thisFriday->month . '月第' . $thisFriday->weekOfMonth . '週';
$this->tag->tag = $nextWeekTag;
$this->tag->save();
}
\Log::info('End generate tag');
} else {
\Log::info('Today is not Friday.');
}
}
示例2: handle
/**
* Handle the event.
*
* @param VoteWasOpened $event
* @return void
*/
public function handle(VoteWasOpened $event)
{
/**
* Queue OpenVoteCommand
*/
$command = new CloseVotingCommand($event->vote);
$delay = $event->vote->close_date->timestamp - $this->carbon->now()->timestamp;
$this->queue->laterOn('voting', $delay, $command);
}
示例3: addPartecipants
/**
* @param $participants
* @param $conversation_id
* @return \Illuminate\Database\Eloquent\Model|static
*/
public function addPartecipants($participants, $conversation_id)
{
$partecipantsConversartion = [];
if (count($participants) > 1) {
foreach ($participants as $key => $partecipant) {
$partecipantsConversartion[$key] = ['conversation_id' => (int) $conversation_id, 'participant_id' => $partecipant, 'created_at' => $this->carbon->now(), 'updated_at' => $this->carbon->now()];
}
$multiPartecipants = true;
} else {
$partecipantsConversartion = ['conversation_id' => $conversation_id, 'participant_id' => $participants[0]];
$multiPartecipants = false;
}
return $this->convJoinedRepo->add($partecipantsConversartion, $multiPartecipants);
}
示例4: store
/**
* Store a newly created Image in storage.
*
* @return Response
*/
public function store()
{
// $a = '>>>|';
// foreach (Request::all() as $key => $value) $a .= $key . ':::' . $value . '|';
// return $a;
$valid_ext = ['jpg', 'png', 'bmp', 'gif', 'jpeg'];
if (!Request::hasFile('image')) {
throw new FileUploadException('image not found');
}
if (!Request::file('image')->isValid()) {
throw new FileUploadException('image is not valid');
}
$params = Request::all();
$file = $params['image'];
unset($params['image']);
if (!in_array($file->getClientOriginalExtension(), $valid_ext)) {
throw new FileUploadException('image type is not valid');
}
$file_name = Carbon::now()->format('Ymd_His_') . $params['title'] . '.' . $file->getClientOriginalExtension();
$file_path = 'images/';
$params['filename'] = $file_name;
$image = new Image($params);
if ($image->save()) {
Storage::put($file_path . $file_name, File::get($file));
return $image;
} else {
throw new CrudException('image:store');
}
}
示例5: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index($userId)
{
$user = User::find($userId);
$runningtimes = User::find($userId)->runningtimes()->orderBy('ran_on', 'desc')->get();
$total_km = 0;
$total_time = 0;
foreach ($runningtimes as $rt) {
$total_km += $rt['distance'];
}
$total_km = sprintf('%05.2f', $total_km);
$av_speed = sprintf('%05.2f', User::find($userId)->runningtimes()->avg('speed'));
$dt = Carbon::now()->subMonths(1);
$good_speeds = 0;
$c = 0;
foreach ($runningtimes as $rt) {
if ($rt['ran_on']->gt($dt) and $rt['ran_on']->lte(Carbon::now())) {
$good_speeds += $rt['speed'];
$c += 1;
}
}
if ($c > 0) {
$av_speed_month = sprintf('%05.2f', $good_speeds / $c);
} else {
$av_speed_month = sprintf('%05.2f', 0);
}
return view('runningtimes.index', ['user' => $user, 'runningtimes' => $runningtimes, 'total_km' => $total_km, 'av_speed' => $av_speed, 'av_speed_month' => $av_speed_month]);
}
示例6: __construct
public function __construct()
{
$this->middleware('ipblocked');
$driver = config('database.default');
$database = config('database.connections');
$this->db = $database[$driver]['database'];
$this->dbuser = $database[$driver]['username'];
$this->dbpass = $database[$driver]['password'];
$this->dbhost = $database[$driver]['host'];
if (\Auth::check() == true) {
if (!\Session::get('gid')) {
\Session::put('uid', \Auth::user()->id);
\Session::put('gid', \Auth::user()->group_id);
\Session::put('eid', \Auth::user()->email);
\Session::put('ll', \Auth::user()->last_login);
\Session::put('fid', \Auth::user()->first_name . ' ' . \Auth::user()->last_name);
\Session::put('themes', 'sximo-light-blue');
}
}
if (!\Session::get('themes')) {
\Session::put('themes', 'sximo');
}
if (defined('CNF_MULTILANG') && CNF_MULTILANG == 1) {
$lang = \Session::get('lang') != "" ? \Session::get('lang') : CNF_LANG;
\App::setLocale($lang);
}
$data = array('last_activity' => strtotime(Carbon::now()));
\DB::table('tb_users')->where('id', \Session::get('uid'))->update($data);
}
示例7: grades
/**
* 成績資料.
*
* @param Request $request
* @return array
*/
protected function grades(Request $request)
{
$key = 'grades-' . md5($request->user()->getAuthIdentifier()) . '-' . $this->courseId;
return Cache::tags('ecourse-lite')->remember($key, Carbon::now()->endOfDay(), function () {
return Grade::lists($this->courseId);
});
}
示例8: store
/**
* Store a newly created book in storage.
*
* @param BookRequest $request
* @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse
*/
public function store(BookRequest $request)
{
$this->book->create($request);
event(new BookHasCreated('Δημιουργία βιβλίου: ' . $request->title, Carbon::now()->format('Y-m-d'), 'http://library.gr/cPanel/unpublished/' . $request->get('barcode') . '/confirm', $this->user->myAdministratorHash(), $request->get('barcode'), 1));
flash()->overlay('Συγχαρητήρια', 'το βιβλίο ' . $request->title . ' δημιουργήθηκε με επιτυχία. Αναμένετε έγκριση από τον διαχειριστή');
return redirect()->back();
}
示例9: postPayment
public function postPayment()
{
// Step 1: Check if the request contains required fields
if (!$this->validatePaymentRequest()) {
$this->response->addMessage('Invalid Payment Request.');
return $this->output();
}
// Step 2: Validation passed -> Create new payment
$payment = new \Payment();
$payment->payment_amount_ex_vat = $this->data['payment_amount_ex_vat'];
$payment->vat_amount = $this->data['vat_amount'];
$payment->gratuity_amount = isset($this->data['gratuity_amount']) ? $this->data['gratuity_amount'] : 0;
$payment->branch_id = $this->data['branch_id'];
$payment->payment_vendor_id = $this->data['payment_vendor_id'];
$payment->employee_id = $this->data['employee_id'];
$payment->order_id = $this->data['order_id'];
$payment->payment_taken_at = $this->data['payment_taken_at'];
$payment->terminal_id = $this->data['terminal_id'];
$payment->created_at = \Carbon\Carbon::now();
// Step 3: Save the payment into the database
if ($payment->save()) {
$this->response->setSuccess(1);
$this->response->setPaymentId($payment->id);
return $this->output();
}
}
示例10: index
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$today = Carbon::today();
$tomorrow = Carbon::tomorrow();
$tomorrowbookinguser = Booking::where('bookingdate', '=', $tomorrow)->get();
$dt = Carbon::now();
$year = $dt->year;
$month = $dt->month;
$currentmonthbreakfast = Booking::where('user_id', Auth::user()->id)->whereMonth('bookingdate', '=', $month)->whereYear('bookingdate', '=', $year)->where('breakfast', '=', 'on')->count();
$currentmonthlunch = Booking::where('user_id', Auth::user()->id)->whereMonth('bookingdate', '=', $month)->whereMonth('bookingdate', '=', $month)->whereYear('bookingdate', '=', $year)->where('lunch', '=', 'on')->count();
$currentmonthdinner = Booking::where('user_id', Auth::user()->id)->whereMonth('bookingdate', '=', $month)->whereMonth('bookingdate', '=', $month)->whereYear('bookingdate', '=', $year)->where('dinner', '=', 'on')->count();
$totalbooking = $currentmonthbreakfast + $currentmonthlunch + $currentmonthdinner;
$price = Account::whereMonth('accountdate', '=', date('m'))->where('user_id', Auth::user()->id)->sum('amount');
$todaydayshop = Shop::where('shopdate', $today)->get();
$tomorrowshop = Shop::where('shopdate', $tomorrow)->get();
$bookings = Booking::where('bookingdate', '=', $today)->get();
$breakfast = Booking::where('bookingdate', '=', $today)->where('breakfast', '=', 'on')->count();
$lunch = Booking::where('bookingdate', '=', $today)->where('lunch', '=', 'on')->count();
$dinner = Booking::where('bookingdate', '=', $today)->where('dinner', '=', 'on')->count();
$t_breakfast = Booking::where('bookingdate', '=', $tomorrow)->where('breakfast', '=', 'on')->count();
$t_lunch = Booking::where('bookingdate', '=', $tomorrow)->where('lunch', '=', 'on')->count();
$t_dinner = Booking::where('bookingdate', '=', $tomorrow)->where('dinner', '=', 'on')->count();
$useraccounts = DB::table('useraccounts')->where('user_id', Auth::user()->id)->select('user_id', DB::raw("SUM(foodamount) AS t_foodamount"), DB::raw("SUM(houserent) AS t_houserent"), DB::raw("SUM(internetbill) AS t_internetbill"), DB::raw("SUM(utlitybill) AS t_utlitybill"), DB::raw("SUM(buabill) AS t_buabill"), DB::raw("SUM(pay) AS t_pay"))->get();
foreach ($useraccounts as $account) {
$amount = $account->t_foodamount + $account->t_houserent + $account->t_internetbill + $account->t_utlitybill + $account->t_buabill;
$balance = $amount - $account->t_pay;
}
return view('home', ['bookings' => $bookings, 'breakfast' => $breakfast, 'lunch' => $lunch, 'dinner' => $dinner, 't_breakfast' => $t_breakfast, 't_lunch' => $t_lunch, 't_dinner' => $t_dinner, 'tomorrow' => $tomorrow, 'todaydayshop' => $todaydayshop, 'tomorrowshop' => $tomorrowshop, 'tomorrowbookinguser' => $tomorrowbookinguser, 'balance' => $balance, 'currentmonthbreakfast' => $currentmonthbreakfast, 'currentmonthlunch' => $currentmonthlunch, 'currentmonthdinner' => $currentmonthdinner, 'totalbooking' => $totalbooking, 'price' => $price]);
}
示例11: run
public function run()
{
DB::table('readings')->delete();
Reading::create(array('device' => 1, 'temp' => 19.5, 'heaton' => 1, 'created_at' => \Carbon\Carbon::now()->subDays(2)->toDateTimeString(), 'updated_at' => \Carbon\Carbon::now()->subDays(2)->toDateTimeString()));
Reading::create(array('device' => 1, 'temp' => 19.7, 'heaton' => 1, 'created_at' => \Carbon\Carbon::now()->subDays(1)->toDateTimeString(), 'updated_at' => \Carbon\Carbon::now()->subDays(1)->toDateTimeString()));
Reading::create(array('device' => 1, 'temp' => 20.1, 'heaton' => 0, 'created_at' => \Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => \Carbon\Carbon::now()->toDateTimeString()));
}
示例12: run
public function run()
{
DB::statement("SET foreign_key_checks = 0");
DB::table('rewards')->delete();
$rewards = [['num_referrals' => 0, 'title' => 'Two Weeks Free', 'description' => 'Sign up to receive two weeks for free', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()], ['num_referrals' => 1, 'title' => 'Additional Two Weeks Free', 'description' => 'Refer 1 friends for an additional two weeks for free', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()], ['num_referrals' => 3, 'title' => 'Additional Month Free', 'description' => 'Refer 3 or more friends for an additional month for free', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]];
DB::table('rewards')->insert($rewards);
}
示例13: customCreate
public static function customCreate(CreateConversationRequest $request)
{
$conv = new Conversation();
$conv->Title = $request->Title;
// if nothing specified in the request
if (!$request->has('user_id')) {
// if we are not even logged ( happen while seeding base)
if (!\Auth::check()) {
$conv->user_id = User::first()->id;
} else {
$conv->user_id = \Auth::id();
}
}
// if Pending status is specified we take it, if not default value will be applied (false)
if (!$request->has('Pending')) {
$conv->Pending = $request->Pending;
}
$conv->created_at = Carbon::now();
$conv->save();
// When conversation is settled the Thread can be created
$thread = new Thread();
$thread->user_id = $conv->user_id;
$thread->Content = $request->Content;
$thread->conversation_id = $conv->id;
$thread->created_at = Carbon::now();
$thread->Pending = $conv->Pending;
$thread->save();
return true;
}
示例14: insertReaction
/**
* Insert reaction in DB (eiter from a Facebook post or Tweet)
* @param string $type
* @param object $mention
* @param integer $id
* @param string $answer
*
* @return Reaction
*/
public function insertReaction($type, $mention, $id, $answer = null)
{
$reaction = new Reaction();
$reaction->publishment_id = $id;
if ($answer != null) {
$reaction->user_id = Auth::user()->id;
}
if ($type == 'twitter') {
if ($mention['user']['id_str'] != Configuration::twitterId()) {
$reaction->user_id = $mention['user']['id_str'];
}
$reaction->screen_name = $mention['user']['screen_name'];
$reaction->tweet_id = $mention['id_str'];
$reaction->tweet_reply_id = $mention['in_reply_to_status_id_str'];
$reaction->message = $mention['text'];
$reaction->post_date = changeDateFormat($mention['created_at']);
} else {
$reaction->fb_post_id = $mention->id;
if ($answer == null) {
$reaction->screen_name = $mention->from->name;
$reaction->message = $mention->message;
$reaction->post_date = changeFbDateFormat($mention->created_time);
} else {
$reaction->message = $answer;
$reaction->post_date = Carbon::now();
}
}
$reaction->save();
return $reaction;
}
示例15: putContent
/**
* Write data to file
*
* @param array $data
* @return bool|int|void
*/
public function putContent($data)
{
if (file_put_contents($this->getFilePath(), $data)) {
$this->setUpdatedAt(Carbon::now()->toDateTimeString());
}
return $this->save();
}