Suppose we have a Forms
directory in public
folder of laravel.
And Now I want to only Authenticated users can access to that and if an unautho
i would say you need to use local disk instead of public folder if you want to hide content from the user. take a look at here https://laravel.com/docs/5.3/filesystem
still if you want to restrict the directory you can use wildcard route
for ex.
Route::get('/forms/{path?}', function () {
if(!auth()->user()) {
return 'unauthorized';
}
// if authenticated try to look for the file with requested path and return its content
return File::get(public_path(ltrim($_SERVER['REQUEST_URI'],'/')));
})->where(['path' => '.*']);