不知道我是不是错过了一些简单的东西(我已经做了很长一段时间了)。我正试着做一本简单的预约书,我有一个简单的桌子,里面有时隙。
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,因为它也是id 2。我怎样才能检查这两种情况,然后从那里出发呢?
发布于 2013-10-12 01:14:32
添加第二个where子句:
$count = Schedule::where('date', '=', $dateFormat)
->where('timeslot', '=', $block->id)
->count();您可以使用$input['timeslot']而不是$block->id (它们应该是相同的)。
https://stackoverflow.com/questions/19329330
复制相似问题