不确定我是否遗漏了一些简单的东西(我已经为此工作了一段时间)。我正在尝试制作一个简单的约会簿,并且设置了一个简单的表格,其中包含时间段
id timeslot montgomery birmingham
1 8-10 2 2
2 9-12 6 3
3 12-3 6 3
4 3-5 2 2
我有这个作为我的控制器
public function getSchedule() {
$user = User::find(Auth::user()->id);
$input = [
'date' => Input::get('date'),
'timeslot' => Input::get('timeslot')
];
$date = strtotime($input['date']);
$dateFormat = date('Y-m-d',$date);
$block = DB::table('bk_timeslot')
->where('id', '=', $input['timeslot'])
->first();
if($user->office == "Birmingham") {
$count = Schedule::where('date', '=', $dateFormat)->count();
$full = "Sorry Birmingham does not have an appointment open for this day";
if ($count >= $block->birmingham) {
return Redirect::to('book/schedule')->withErrors($full)->withInput();
}
}
if($user->office == "Montgomery") {
$count = Schedule::where('date', '=', $dateFormat)
->count();
var_dump($count); die;
$full = "Sorry Montgomery does not have an appointment open for this day";
if ($count >= $block->montgomery) {
return Redirect::to('book/schedule')->withErrors($full)->withInput();
}
}
//puts info in a session for later use
Session::put('schedule', $input);
return Redirect::to('book/review');
}
除了这一行之外,一切都很好:
$count = Schedule::where('date', '=', $dateFormat)->count();
它正在做的是计算一整天,而不是检查时间段是否也在占用:
进度表的结构
id date timeslot
1 2013-10-11 1
1 2013-10-11 1
1 2013-10-11 4
因此,如果您尝试在 10-11 预订 8-10 的时间段,您将无法预订,因为它已满……这很好,但您也无法预订 3-5,因为它也是 2 号。我如何检查两者并从那里继续?