user2194246
user2194246

Reputation: 203

laravel prevent unauthenticated users from viewing the files

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 ?

Upvotes: 0

Views: 661

Answers (1)

searsaw
searsaw

Reputation: 3632

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.

Upvotes: 1

Related Questions