好吧首先,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');
}
現在