gpt4 book ai didi

php - 如何从数据库检索数据并在 View 页面中按月份显示

转载 作者:行者123 更新时间:2023-11-29 21:36:07 27 4
gpt4 key购买 nike

我有一个名为 Reservation 的表

id | property_id | name | checkin_date | checkout_date | guests

1 | 1 | Tim | 2016-01-10 | 2016-01-15 | 3
2 | 2 | Alex | 2016-01-16 | 2016-01-26 | 5
3 | 1 | Kevin | 2016-01-28 | 2016-02-10 | 3

等等。

我需要根据月份显示 checkin 日期和结帐日期,如果日期在两个月之间,结果应在这两个月份中显示......我在 View 页面中的预期输出是

January

2016-01-10 To 2016-01-15 Tim Booked
2016-01-16 To 2016-01-26 Alex Booked
2016-01-28 To 2016-01-31 Kevin Booked

February

2016-02-01 To 2016-02-10 Kevin Booked


March, April,June...etc

我已经完成了一些部分编码。

在我的 Controller 中

public function index{

for($i=1; $i<=12; i++){
$("reservation".$i)=Reservation::whereMonth('checkin_date','=',$i)
->get();
}
return view('abc',compact(reservation1,reservation2));
}

在我的 View 文件中

<h3>January</h3>
<?php foreach($reservation1 as $january){ ?>
<?php echo $january->checkin_date; ?> To <?php echo $january->checkout_date; ?> <?php echo $january->name; ?> Booked

请有人帮助我获得输出...提前致谢

最佳答案

您需要这个库 FullCalendar

Controller

public function test(){
$events = [];
//creating events
$events[] = \Calendar::event(
'Angel', //event title
true, //full day event?
'2016-01-01', //start time (you can also use Carbon instead of DateTime)
'2016-01-03', //end time (you can also use Carbon instead of DateTime)
1, //optionally, you can specify an event ID
[
'backgroundColor' => '#ff5722'
]
);
$events[] = \Calendar::event(
'Jesus', //event title
true, //full day event?
'2016-01-04', //start time (you can also use Carbon instead of DateTime)
'2016-01-08', //end time (you can also use Carbon instead of DateTime)
1, //optionally, you can specify an event ID
[
'backgroundColor' => '#e97118'
]
);
//adding events
$calendar = \Calendar::addEvents($events)->setOptions(['lang' => 'es']);

return view('pages.calendar')->with('calendar',$calendar);
}

查看(最好使用 Blade )

 <div class="row">
<div class="col-md-12">
{!! $calendar->calendar() !!}
{!! $calendar->script() !!}
</div>
</div>

结果 enter image description here

关于php - 如何从数据库检索数据并在 View 页面中按月份显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34906561/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com