在我的登录表单中我想设置检查会话超时填写表格,填写表格后,我想查看很长时间,如果会话过期表格必须重新创建以填写用户,我使用此方法但我得到错误:
我的代码:
public function checkAccount(CheckAuthenticationRequest $request)
{
if ((time() - Session::activity()) > (Config::get('session.lifetime') * 60))
{
return redirect()->back()
->withErrors('Login form no longer fill, you must be fill again')
->withInput();
}
...
}
错误:用于代码
call_user_func_array()期望参数1是有效的回调, class' Illuminate \ Session \ Store'没有方法'活动'
错误:如果我的表单不再由用户填写并尝试发送表单数据
TokenMismatchException
答案 0 :(得分:0)
错误表明Session没有您正在调用的方法。试试Session::get('lastActivityTime')
通过设置会话来实施lastActivityTime
:Session::set('lastActivityTime', time())
答案 1 :(得分:0)
你可以这样做。
class formController extends Controller{
/**FUNCTION THAT RETURNS THE FORM VIEW**/
public function showForm(Request $request) {
$request->session()->put("opendate", Carbon::now()); //put current timestamp in the session
return view("myform");
}
/**FUNCTION THAT HANDLES THE FORM DATA**/
public function public function checkAccount(Request $request){
if(!$request->session()->has("opendate")) return abort(400);
$open_date = $request->session()->pull("opendate");
//check the difference between data in the session and now
if($opendate->diffInMinutes(Carbon::now()) > 10) //<-- expire minutes here)
return redirect()->back()
->withErrors("Login form no longer fill, you must be fill again")
->withInput();
//success code here
}
}