我是laravel的新手,无法在直接访问页面网址之前检查用户是否已登录。
I suppose the check should be done in the routes and there is no problem to do so when calling a view from the route:
Route::get('/', function()
{
if (!Session::has('loggedOn'))
{
return view('viewLogin');
}
else
{
return view('viewAllData');
}
});
enter code here
But when I want to call a Controller and check if (!Session::has('loggedOn')), how is this done?
Route::get('/messagesPage', 'MsgsController@messages');
答案 0 :(得分:2)
以下将查看用户是否已登录
添加
rootDir=r"path to your directory"
for dirName,subDir, fileList in os.walk(rootDir, topdown=False):
merger = PdfFileMerger()
for fname in fileList:
merger.append(PdfFileReader(open(os.path.join(dirName, fname),'rb')))
merger.write(str(dirName)+".pdf")
到你的控制器和下面的检查
use Illuminate\Support\Facades\Auth;
编辑以添加第二个问题的答案
if (Auth::check()) {
// The user is logged in...
}
以上只会让用户在登录时访问路径