in my login form i would like to set check session timeout for filling form, after fill form, i want to check long time, if session expired form must be recreate to fill by user, i'm using this method but i get error:
My code:
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();
}
...
}
Error: for use above code
call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Session\Store' does not have a method 'activity'
Error: if my form no longer fill by user and try to send form data
TokenMismatchException
The error states that Session doesn't have the method you are calling. Try with Session::get('lastActivityTime')
Implement lastActivityTime
by setting the session like so: Session::set('lastActivityTime', time())
You can do something like that.
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
}
}