本文整理汇总了PHP中Carbon\Carbon::subHours方法的典型用法代码示例。如果您正苦于以下问题:PHP Carbon::subHours方法的具体用法?PHP Carbon::subHours怎么用?PHP Carbon::subHours使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Carbon\Carbon
的用法示例。
在下文中一共展示了Carbon::subHours方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: scopeCompleted
/**
* Scope a query to only contain battles that are closed for voting
*/
public function scopeCompleted($query)
{
$votingperiod = config('rap-battle.votingperiod', 24);
// battles before this date are closed:
$timeoldest = new Carbon();
$timeoldest->subHours($votingperiod);
return $query->where('created_at', '<', $timeoldest->toDateTimeString());
}
示例2: scopeUnread
/**
* Is this notification "read"? (we assume that it is after 6 hours, or if the user clicked open the notification menu)
*
* @param $query
* @param $user_id
* @return mixed
*/
public function scopeUnread($query, $user_id)
{
$date = new Carbon();
$date->subHours(6);
return $query->where('user_id', '=', $user_id)->where('is_read', '=', 0)->orWhere('created_at', '>', $date->toDateTimeString())->get();
}
示例3: store
public function store(ReservationRequest $request)
{
//booking
$booking = array('car_type_id' => $request->car_type_id, 'number_of_passengers' => $request->number_of_passengers, 'pickup_time' => $request->pickup_date_part . ' ' . $request->pickup_time_part);
$newBooking = Booking::create($booking);
// main passenger
//user (main passenger)
$mainpassenger = new User();
$mainpassenger->name = $request->name;
$mainpassenger->phone = $request->phone;
$mainpassenger->save();
//role (main passenger)
$role = array('booking_id' => $newBooking->id, 'role_type_id' => '2', 'user_id' => $mainpassenger->id);
Role::create($role);
//email receiver
//user (email receiver)
$emailreceiver = User::firstOrCreate(['email' => $request->email]);
//role (email receiver)
$role = array('booking_id' => $newBooking->id, 'role_type_id' => '5', 'user_id' => $emailreceiver->id);
Role::create($role);
//route points
//start
$route_point = array('booking_id' => $newBooking->id, 'location_id' => $request->start_location_id, 'sub_location_id' => $request->start_sub_location_id, 'description' => $request->start_description, 'order' => 1);
Route_point::create($route_point);
//via points
$descriptionArray = $request->description;
//if via array is not empty
if (!empty($request->location_id)) {
foreach ($request->location_id as $order => $location_id) {
$route_point = null;
$route_point = array('booking_id' => $newBooking->id, 'location_id' => $location_id, 'description' => $descriptionArray[$order], 'order' => $order);
Route_point::create($route_point);
}
}
//end
$route_point = null;
$route_point = array('booking_id' => $newBooking->id, 'location_id' => $request->end_location_id, 'description' => $request->end_description, 'order' => 99);
Route_point::create($route_point);
//general comment
if (!empty($request->comment)) {
$comment = array('booking_id' => $newBooking->id, 'comment_type_id' => '2', 'role_id' => '1', 'comment' => $request->comment);
Comment::create($comment);
}
//price
$price = Income_list::where('car_type_id', $request->car_type_id)->where('direction_id', $request->direction_id)->where('income_type_id', 1)->whereNull('user_id')->first();
$income = array('booking_id' => $newBooking->id, 'income_type_id' => '1', 'amount_eur' => $price->amount_eur);
Income::create($income);
//cashflow
if ($request->payment_type_id == 3) {
$receiver_id = 1;
//receiver is driver
$due_date = $newBooking->pickup_time;
//on the day of travel
} else {
$receiver_id = 4;
//receiver is us (admin)
$pickup_time = new Carbon($newBooking->pickup_time);
$due_date = $pickup_time->subHours(48);
//48 hours before trip
}
$cashflow = array('booking_id' => $newBooking->id, 'payer_id' => 2, 'receiver_id' => $receiver_id, 'payment_type_id' => $request->payment_type_id, 'payment_status_id' => 1, 'amount_eur' => $price->amount_eur, 'due_date' => $due_date);
Cashflow::create($cashflow);
//log reservation creation
$change = array('booking_id' => $newBooking->id, 'change_type_id' => '4', 'user_id' => 1, 'from' => null, 'to' => null);
Change::create($change);
//send email
Mail::queue('emails.reservation', ['passenger' => $mainpassenger], function ($message) use($emailreceiver) {
$message->from('info@transferpraha.cz', 'Transfer Praha')->to($emailreceiver->email, null)->subject('Booking confirmation');
});
flash()->success('Your booking has been created!')->important();
return redirect('reservation/confirmation');
}
示例4: testScopesOpenCompleted
/**
* Test for scopeOpenVoting and scopeCompleted
*/
public function testScopesOpenCompleted()
{
// create rappers
$user1 = factory(App\Models\User::class)->create();
$user2 = factory(App\Models\User::class)->create();
$votingperiod = config('rap-battle.votingperiod', 24);
// battles older than this date are closed:
$timeoldest = new Carbon();
$timeoldest->subHours($votingperiod + 1);
// create two battles
$battle1 = new Battle();
$battle1->rapper1_id = $user1->id;
$battle1->rapper2_id = $user2->id;
$battle1->save();
$battle2 = new Battle();
$battle2->rapper1_id = $user1->id;
$battle2->rapper2_id = $user2->id;
$battle2->created_at = $timeoldest->toDateTimeString();
$battle2->save();
// test scopeOpenVoting
// get battles from database
$openBattles = Battle::openVoting()->get()->values()->keyBy('id');
$this->assertTrue($openBattles->has($battle1->id));
$this->assertFalse($openBattles->has($battle2->id));
// test scopeCompleted
// get battles from database
$completedBattles = Battle::completed()->get()->values()->keyBy('id');
$this->assertFalse($completedBattles->has($battle1->id));
$this->assertTrue($completedBattles->has($battle2->id));
}
示例5: testGetCompleted
/**
* Test for getCompleted
*/
public function testGetCompleted()
{
$user1 = factory(App\Models\User::class)->create();
$user2 = factory(App\Models\User::class)->create();
$user3 = factory(App\Models\User::class)->create();
$user4 = factory(App\Models\User::class)->create();
$votingperiod = Config::get('rap-battle.votingperiod', 24);
// battles older than this date are closed:
$timeoldest = new Carbon();
$timeoldest->subHours($votingperiod + 1);
// create two battles
$battle1 = new Battle();
$battle1->rapper1_id = $user1->id;
$battle1->rapper2_id = $user2->id;
$battle1->video = "/path/to/file";
$battle1->save();
$battle2 = new Battle();
$battle2->rapper1_id = $user3->id;
$battle2->rapper2_id = $user4->id;
$battle2->video = "/path/to/file";
$battle2->created_at = $timeoldest->toDateTimeString();
$battle2->save();
$this->get('/battles/completed')->seeJson(['current_page' => 1, 'data' => [['battle_id' => (string) $battle2->id, 'rapper1' => ['user_id' => (string) $user3->id, 'username' => $user3->username, 'profile_picture' => $user3->picture], 'rapper2' => ['user_id' => (string) $user4->id, 'username' => $user4->username, 'profile_picture' => $user4->picture]]]]);
}
示例6: GetPopularProfiles
public function GetPopularProfiles($limit)
{
$date = new Carbon();
$date->subHours(1);
return Profile::where('is_active', true)->orderBy('created_at', 'DESC')->take($limit)->get();
}