我以前从未使用过会话,我正在尝试找出处理此问题的最佳方法。我基本上正在尝试做:
选择服务的第一步
2步选择时间
3 步审查和书籍
我可以使用 mysql 让它毫无问题地工作。我通常会做的是在每一步之后将信息保存到数据库中,当我进入审查部分时,我会保存所有信息并且没问题。
但是,我认为这不是解决此问题的最佳方法,并且可能会导致以后出现问题(如果他们停在第 2 步等等怎么办)
我决定尝试 Laravel 4 会话,保存会话并继续下一步非常容易。但是,当我到达最后一步时,我需要加入 mysql 表以完全显示有关他们的预订信息。我可以使用会话信息来加入信息吗?我可以使用会话数据库来保存这些信息吗?或者使用不同的表?
我的控制器在查看信息后发布:
public function getReview() {
//sets id of user
$user = User::find(Auth::user()->id);
//gets the time and date that they booked from @getSchedule
$scheduler = Session::get('schedule');
//formats time to put in db
$date = strtotime($scheduler['date']);
//same thing as the line above
$dateFormat = date('Y-m-d',$date);
//model to save the schedule
$schedule = new Schedule();
$schedule->userID = $user->id;
$schedule->date = $dateFormat;
$schedule->block = $scheduler['timeslot'];
$schedule->status = "1";
$schedule->save();
//gets the services the user picked from @getServices
$service = Session::get('service');
//saves the services as individual rows in db table
foreach($service as $services)
{
if(!empty($services)) {
$service = new Service();
$service->userID = $user->id;
$service->services = $services;
$service->save();
}
}
return Redirect::to('dashboard');
}
这是 GET 评论页面(我遇到了所有 JOINS 的问题)
public function showReview() {
$user = User::find(Auth::user()->id);
//show the information and confirm that they want all this crap...if they do..save it and return them to their dashboard
$time = DB::table('bk_schedule')
->leftJoin('bk_timeslot', 'bk_schedule.block', '=', 'bk_timeslot.id')
->where('bk_schedule.id', Auth::user()->id)->first();
$date = strtotime($time->date);
$dateFormat = date('D: F d, Y',$date);
$service = Session::get('service');
$serviceSummary = DB::table('bk_service')
->leftJoin('pr_service', 'pr_service.id', '=', 'bk_service.services')
->where('bk_service.userID', Auth::user()->id)
->get();
$total = DB::table('bk_service')
->leftJoin('pr_service', 'pr_service.id', '=', 'bk_service.services')
->where('bk_service.userID', Auth::user()->id)
->sum('pr_service.price');
return View::make('book.review', array('pageTitle' => 'Booking Appointment Review and Finalize', 'service' => $service, 'date' => $dateFormat,
'time' => $time, 'email' => $user->email, 'serviceSummary' => $serviceSummary, 'total' => $total));
}
如果他们不提交到POST,是否可以将信息保存在GET并删除它?我可以使用我的会话数据并使用我拥有的 MySQL 查询吗?