如何在laravel检查今天的日期和时间

时间:2016-10-09 03:57:18

标签: php mysql laravel date

我做了一个项目。在我的项目中,我想在时间和日期是当前日期和时间时显示一个开始按钮。今天说是10月9日。如果用户在10月9日上午10点到12点给出序列号,则开始按钮将仅显示10月9日上午10点到12点。我该怎么做到这一点。 我的观点是

<a class="btn btn-info" style="margin-right: 0" href="{{ URL::to('booking/reject/'.$booking->id) }}">Reject</a>
@elseif ( !empty($booking->is_accepted) && $booking->is_accepted == 1)
 <a class="btn btn-info" style="margin-right: 0">Accepted</a>

<a class="btn btn-info" style="margin-right: 0" href="http://devteam.website/esp+hadfkku+hhj2hjh2+q+web+video+calling/index.php?r=videochat/login">Start</a>
@elseif ( !empty($booking->is_accepted) && $booking->is_accepted == 2)
   <a class="btn btn-info" style="margin-right: 0">Rejected</a>
@endif

我的控制器是

public function profile($username) {
        $username_exists = User::where('username', $username)->first();
        if (!empty($username_exists)) {
            if (Auth::check()) {
                $username_exists->no_of_viewer = $username_exists->no_of_viewer + 1 ;
                $username_exists->save() ;
                if (UserRole::where('user_id', Auth::user()->id)->first()->role_id == 2) {
                    $bookings = Booking::where('provider_id', Auth::user()->id)->orderBy('id', 'desc')->get();
                } elseif (UserRole::where('user_id', Auth::user()->id)->first()->role_id == 3) {
                    $bookings = Booking::where('provider_id', Auth::user()->id)->orderBy('id', 'desc')->get();
                } else {
                    $bookings = '';
                }

                $payments = Payment::where('user_id', Auth::user()->id)->orWhere('provider_id', Auth::user()->id)->get();
            }
            $data = [
                'user' => $username_exists,
                'user_detail' => UserDetail::where('user_id', $username_exists->id)->first(),
                'user_share' => UserShare::where('user_id', $username_exists->id)->first(),
                'user_work_experiences' => UserWorkExperience::where('user_id', $username_exists->id)->where('is_deleted', 0)->get(),
                'user_academic_experiences' => UserAcademicExperience::where('user_id', $username_exists->id)->where('is_deleted', 0)->get(),
                'user_meetings' => UserMeeting::where('user_id', $username_exists->id)->first(),
                'user_time' => UserTime::where('user_id', $username_exists->id)->first(),
                'bookings' => (!empty($bookings)) ? $bookings : '',
                'reviews' => Review::where('provider_id', $username_exists->id)->get(),
                'rating' => Review::where('provider_id', $username_exists->id)->avg('rating'),
                'payments' => !empty($payments)?$payments:''
            ];
            return view('frontends.profile', $data);
        } else {
            return view('errors.503');
        }
    }

请帮忙

1 个答案:

答案 0 :(得分:0)

$dt = new DateTime();

echo $dt->format('Y-m-d H:i:s');

  

或:

$mytime = Carbon\Carbon::now();

echo $mytime->toDateTimeString();