好的,首先,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', 'StoreController@flushSession');
});
现在您已限制对 url 的访问并检查了会话。
现在
public function flushSession()
{
//empty out the session and
return redirect()->to('/home');
}