PHPackages                             kommandhub/laravel-folder-protection - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. kommandhub/laravel-folder-protection

ActiveLibrary[Security](/categories/security)

kommandhub/laravel-folder-protection
====================================

A Laravel package for basic folder protection using basic auth, specifically for staging environments.

v1.0.0(3mo ago)09MITPHPPHP ^8.2CI passing

Since Mar 15Pushed 3mo agoCompare

[ Source](https://github.com/KommandHub/laravel-folder-protection)[ Packagist](https://packagist.org/packages/kommandhub/laravel-folder-protection)[ RSS](/packages/kommandhub-laravel-folder-protection/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (1)Dependencies (6)Versions (3)Used By (0)

Laravel Folder Protection
=========================

[](#laravel-folder-protection)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a78a722fc699cb38c05383d9d029fe5ccfff1d64b6bde90442059c7f45ac97de/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b6f6d6d616e646875622f6c61726176656c2d666f6c6465722d70726f74656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kommandhub/laravel-folder-protection)[![GitHub Tests Action Status](https://camo.githubusercontent.com/45ba1a65039e2c0169f78843c094cc8734ee08625b344221bc5ba706dc59b766/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6b6f6d6d616e646875622f6c61726176656c2d666f6c6465722d70726f74656374696f6e2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/kommandhub/laravel-folder-protection/actions)[![Total Downloads](https://camo.githubusercontent.com/e149638da509b064f7b13a5fa99185dfdac8b4b099801ae940cb3eae0b6b8d83/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b6f6d6d616e646875622f6c61726176656c2d666f6c6465722d70726f74656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kommandhub/laravel-folder-protection)

A simple Laravel package to protect your application (or specific routes) with Basic Authentication. This is particularly useful for staging or preview environments where you want to restrict access without setting up complex authentication.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require kommandhub/laravel-folder-protection
```

The service provider will automatically register itself.

### Publish Configuration

[](#publish-configuration)

You can publish the configuration file using:

```
php artisan vendor:publish --tag="folder-protection-config"
```

This will create a `config/folder-protection.php` file in your application.

Configuration
-------------

[](#configuration)

You can configure the protection using environment variables in your `.env` file:

```
FOLDER_PROTECTION_ENABLED=true
FOLDER_PROTECTION_USER=your_username
FOLDER_PROTECTION_PASSWORD=your_password
```

### Default Behavior

[](#default-behavior)

By default, the protection is enabled only when `APP_ENV` is set to `staging`.

Environment VariableDescriptionDefault`FOLDER_PROTECTION_ENABLED`Enable or disable the protection`config('app.env') === 'staging'``FOLDER_PROTECTION_USER`The username for Basic Auth`null``FOLDER_PROTECTION_PASSWORD`The password for Basic Auth`null`*Note: The package also supports `APP_FOLDER_PROTECTION_USER` and `APP_FOLDER_PROTECTION_PASSWORD` for backward compatibility.*

Usage
-----

[](#usage)

### Global Middleware

[](#global-middleware)

To protect your entire application, add the middleware to your `bootstrap/app.php` (Laravel 11+) or `app/Http/Kernel.php` (Laravel 10 and below).

#### Laravel 11 &amp; 12

[](#laravel-11--12)

```
// bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
    $middleware->append(\KommandHub\FolderProtection\Http\Middleware\FolderProtection::class);
})
```

#### Laravel 10 and below

[](#laravel-10-and-below)

```
// app/Http/Kernel.php
protected $middleware = [
    // ...
    \KommandHub\FolderProtection\Http\Middleware\FolderProtection::class,
];
```

### Route-specific Middleware

[](#route-specific-middleware)

You can also apply the middleware to specific routes or groups:

```
Route::middleware([\KommandHub\FolderProtection\Http\Middleware\FolderProtection::class])->group(function () {
    Route::get('/staging-only', function () {
        // ...
    });
});
```

Testing
-------

[](#testing)

```
composer test
```

### Code Coverage

[](#code-coverage)

To run tests with code coverage (requires Xdebug or PCOV):

```
composer test:coverage
```

The coverage reports will be generated in `build/coverage`.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [KommandHub](https://github.com/kommandhub)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance80

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

103d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0f1debdb2d793fd382ffc606ad8ed6433c9e8b70a9eda51a58227625a2ba412b?d=identicon)[kommandhub](/maintainers/kommandhub)

---

Top Contributors

[![KommandHub](https://avatars.githubusercontent.com/u/225087266?v=4)](https://github.com/KommandHub "KommandHub (9 commits)")

---

Tags

developerdeveloper-toolsdevelopment-environmentlaravellaravel-packagestagingphplaravelgithubdeveloper-toolsopen-sourcekommandhub

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/kommandhub-laravel-folder-protection/health.svg)

```
[![Health](https://phpackages.com/badges/kommandhub-laravel-folder-protection/health.svg)](https://phpackages.com/packages/kommandhub-laravel-folder-protection)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k51.0M7.6k](/packages/larastan-larastan)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[laravel/reverb

Laravel Reverb provides a real-time WebSocket communication backend for Laravel applications.

1.6k12.9M71](/packages/laravel-reverb)[moonshine/moonshine

Laravel administration panel

1.3k239.9k76](/packages/moonshine-moonshine)[illuminate/routing

The Illuminate Routing package.

1239.0M2.8k](/packages/illuminate-routing)[spatie/laravel-export

Create a static site bundle from a Laravel app

672139.5k6](/packages/spatie-laravel-export)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
