public function getCheckuser() { $sessionfb = Session::get('sessionfb'); dd($sessionfb); $userfb = Session::get('userfb'); $check = User::checkuser($userfb, $nh); //kiem tra id nha hang //kiem tra check, neu khong co nguoi dung trong db if ($check == false) { if (!NhaHang::checkid($nh)) { return Redirect::to('/error'); } else { DB::beginTransaction(); try { $user = User::createuser($userfb, htmlentities($_SERVER['HTTP_USER_AGENT']), $nh); $code = Code::createcode($userfb, $type, $nh); DB::commit(); } catch (Exception $e) { //If there are any exceptions, rollback the transaction DB::rollback(); } //Everything worked perfectly. Commit the transaction $user = $userfb->asArray(); $user['fb_id'] = $user['id']; Session::put('user', (object) $user); return Redirect::to('/hello'); } } else { $user = $check; $user->save(); $c = false; $arrs = Code::where('fb_id', $user->fb_id)->get(); foreach ($arrs as $arr) { if ($nh == $arr->nhahang_id) { $c = true; break; } } if (!$c) { $code = Code::createcode($userfb, $type, $nh); Session::put('user', $user); return Redirect::to('/hello'); } else { Session::put('user', $user); return Redirect::to('/hello'); } } }