Php 我如何检查拉雷维尔两个日期之间的差异?
您好,我是新来拉维尔的,我试图建立我的预订应用程序,现在我有一些问题。当我想检查免费房间时,它不检查日期,我可以选择一个否定的日期 在此屏幕中,您可以看到我写的内容 这是我的控制器。在这里,我在预订表上更改日期,只显示免费房间Php 我如何检查拉雷维尔两个日期之间的差异?,php,laravel-5,Php,Laravel 5,您好,我是新来拉维尔的,我试图建立我的预订应用程序,现在我有一些问题。当我想检查免费房间时,它不检查日期,我可以选择一个否定的日期 在此屏幕中,您可以看到我写的内容 这是我的控制器。在这里,我在预订表上更改日期,只显示免费房间 { public function index(Request $request) { if (!Gate::allows('find_room_access')) { return abort(401);
{
public function index(Request $request)
{
if (!Gate::allows('find_room_access')) {
return abort(401);
}
$time_from = $request->input('time_from');
$time_to = $request->input('time_to');
if ($request->isMethod('POST')) {
$rooms = Room::with('booking')->whereHas('booking', function ($q) use ($time_from, $time_to) {
$q->where(function ($q2) use ($time_from, $time_to) {
$q2->where('time_from', '>=', $time_to)
->orWhere('time_to', '<=', $time_from);
});
})->orWhereDoesntHave('booking')->get();
} else {
$rooms = null;
}
return view('admin.find_rooms.index', compact('rooms', 'time_from', 'time_to'));
}
}
{
公共功能索引(请求$Request)
{
如果(!Gate::允许('find_room_access')){
返回中止(401);
}
$time_from=$request->input('time_from');
$time_to=$request->input('time_to');
如果($request->isMethod('POST')){
$rooms=Room::with('booking')->where has('booking',function($q)use($time\u from,$time\u to){
$q->where(函数($q2)使用($time\u from,$time\u to){
$q2->where('time\u from','>=',$time\u to)
->或where('time\u to'、'post'、'route'=>['admin.find\u rooms.index']])
{!!Form::label('time_from',trans('quickadmin.bookings.fields.time from').*',['class'=>'control label'])
{!!Form::text('time_from',old('time_from'),['class'=>'表单控件日期时间选择器','占位符'=>'','必需'=>''])
@如果($errors->has('time_from'))
{{$errors->first('time_from')}
@恩迪夫
{!!Form::label('time_to',trans('quickadmin.bookings.fields.time to').*',['class'=>'control label'])
{!!Form::text('time_-to',old('time_-to'),['class'=>'表单控件日期时间选择器','占位符'=>'','必需'=>''])
@如果($errors->has('time_to'))
{{$errors->first('time_to')}
@恩迪夫
{!!表单::提交('搜索房间',['class'=>'btn btn danger btn block'])
{!!Form::close()!!}
@if(isset($rooms)和is_null($rooms))
@lang('quickadmin.find room.no_rooms_found')
@恩迪夫
@如果(!为空($rooms))
@lang('quickadmin.rooms.fields.roomnumber')
@lang('quickadmin.rooms.fields.floor')
@lang('quickadmin.rooms.fields.description')
每晚价格
@foreach($room作为$room)
{{$room->room_number}
{{$room->floor}
{!!$room->description!!}
{!!$room->price!!}
@can('booking_create')
@恩德坎
@endforeach
@恩迪夫
@停止
@节(“javascript”)
@母公司
$('.datetimepicker').datetimepicker({
格式:“YYYY-MM-DD HH:MM”
});
@停止
您可以使用Validator验证输入字段和日期输入
看看这个
$rules = array(
'date_start' => 'required|date_format:Y-m-d|before_or_equal:date_end',
'date_end' => 'required|date_format:Y-m-d|after_or_equal:date_start'
);
$validator = Validator::make($request->all(), $rules);
$rules = array(
'date_start' => 'required|date_format:Y-m-d|before_or_equal:date_end',
'date_end' => 'required|date_format:Y-m-d|after_or_equal:date_start'
);
$validator = Validator::make($request->all(), $rules);