好吧首先,Bruuuhhhh been there and done that
好吧,让我们开始。你想要的是,如果已经有一个会话store_id
正在进行,那么你希望用户重定向或发回。
在您的控制器添加此
public function initiate()
{
if(session()->has('store_id'))
{
//What ever your logic
}
else
{
redirect()->to('/store')->withErrors(['check' => "You have session activated for here!."]);
}
}
最有可能你会想知道的是用户可以直接去其他网址后/store/other-urls
耶士他能。
为了避免这种情况。在主商店页面添加自定义middleware
php artisan make:middleware SessionOfStore //You can name it anything.
在中间件
public function handle($request, Closure $next)
{
if($request->session()->has('store_id'))
{
return $next($request);
}
else
{
return redirect()->back()->withErrors(['privilege_check' => "You are not privileged to go there!."]);
}
return '/home';
}
。添加anchor tag
<a href="/stop">Stop Service</a>
现在,在您web.php
Route::group(['middleware' => 'SessionOfStore'], function()
{
//Add your routes here.
Route::get('/stop', '[email protected]');
});
现在你必须限制访问的URL,并检查了会议。
在
public function flushSession()
{
//empty out the session and
return redirect()->to('/home');
}
现在