Laravel, protecting a folder in public folder

marmahan :

I have a folder inside the public folder in Laravel app, this folder is called 'docs' and I want to protect it from unauthorised access. So basically when a user tries to access this folder they should get redirected to the login page. I tried doing this:

Route::get('\docs','DocsController@protected')->middleware('auth');

But Laravel doesn't even get triggered and the user goes directly to the folder.

CrayD :

You can use .htaccess file to protect this folder. But IMHO the better way is to move this folder from public, and access the docs using php code (using something like thephpleague/flysystem).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=12384&siteId=1