laravel防止未经身份验证的用户查看文件

I want to try to make some route filter using pattern filter, but it's doesn't work. How to make a route to prevent unauthenticated users from viewing files on specific folder ?

Try this:

Route::get('/directory/{file}', array('before' => 'auth', function($file)
{
    return public_path() . "/directory/$file";
}));

Change directory to whatever the directory is you are trying to protect. Also, I assumed the files you want to deal out are in your public directory. That may need to be changed too, depending on your usage.

Auth is a filter that is already created in a default install of Laravel. It just makes sure they aren't a "guest." It will only let people access the directory if they are "logged in." I believe it looks for a cookie that Laravel sets when you log someone in.