PHPackages                             spatie/laravel-demo-mode - 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. spatie/laravel-demo-mode

Abandoned → [laravel/framework](/?search=laravel%2Fframework)ArchivedLibrary[Security](/categories/security)

spatie/laravel-demo-mode
========================

A middleware to protect your work in progress from prying eyes

2.7.3(3y ago)294111.5k↓21.2%252MITPHPPHP ^8.0.2|^8.1

Since Mar 24Pushed 2y ago9 watchersCompare

[ Source](https://github.com/spatie/laravel-demo-mode)[ Packagist](https://packagist.org/packages/spatie/laravel-demo-mode)[ Docs](https://github.com/spatie/laravel-demo-mode)[ Fund](https://spatie.be/open-source/support-us)[ RSS](/packages/spatie-laravel-demo-mode/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (24)Used By (2)

A middleware to protect your work in progress from prying eyes
==============================================================

[](#a-middleware-to-protect-your-work-in-progress-from-prying-eyes)

[![Latest Version on Packagist](https://camo.githubusercontent.com/764ddd90cb9a1ef8cd26c262680b1d56709feafcedc54ab037f14a4e59eaa6f5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d64656d6f2d6d6f64652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-demo-mode)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/34e0a77103e35dedf7f1fdac906168836b914a1a1f6045a8d882a60e976583d8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d64656d6f2d6d6f64652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-demo-mode)

Imagine you are working on a new app. Your client wants to see the progress that you've made. However your site isn't ready for prime time yet. Sure, you could create some login functionality and display the site only to logged in users. But why bother creating users when there is a more pragmatic approach?

This package provides a route middleware to protected routes from prying eyes. All users that visit a protected route will be redirect to a configurable url (e.g. `/under-construction`). This is also the case when a user attempts to access an unknown route. To view the content of the routes a visitor must first visit a url that grants access (e.g. `/demo`).

A word to the wise: do not use this package to restrict access to sensitive data or to protect an admin section. For those cases you should use proper authentication.

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Notice
------

[](#notice)

If you're on Laravel 8 or higher, use Laravel's built in `php artisan down` command to activate demo mode. You don't need this package for that.

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/304c642a6c3b7d750a0a8db14208ad7c0e68dde5fa7c0fc176ba3462524ece0f/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d64656d6f2d6d6f64652e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-demo-mode)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

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

[](#installation)

You can install the package via composer:

```
composer require spatie/laravel-demo-mode
```

The `Spatie\DemoMode\DemoModeServiceProvider::class` service provider will be auto registered.

The `\Spatie\DemoMode\DemoMode::class`-middleware must be registered in the kernel:

```
//app/Http/Kernel.php

protected $routeMiddleware = [
  ...
  'demoMode' => \Spatie\DemoMode\DemoMode::class,
];
```

Naming the route middleware `DemoMode` is just a suggestion. You can give it any name you'd like.

You must publish the config file:

```
php artisan vendor:publish --provider="Spatie\DemoMode\DemoModeServiceProvider"
```

This is the content of the published config file `demo-mode.php`:

```
return [

    /*
     * This is the master switch to enable demo mode.
     */
    'enabled' => env('DEMO_MODE_ENABLED', true),

    /*
     * Visitors browsing a protected url will be redirected to this path.
     */
    'redirect_unauthorized_users_to_url' => '/under-construction',

    /*
     * After having gained access, visitors will be redirected to this path.
     */
    'redirect_authorized_users_to_url' => '/',

    /*
     * The following IP's will automatically gain access to the
     * app without having to visit the `demoAccess` route.
     */
    'authorized_ips' => [
        //
    ],

    /*
     * When strict mode is enabled, only IP's listed in `authorized_ips` will gain access.
     * Visitors won't be able to gain access by visiting the `demoAccess` route anymore.
     */
    'strict_mode' => false,
];
```

If you want to use the `demoAccess` route you must call the `demoAccess` route macro in your routes file.

```
Route::demoAccess('/demo');
```

Visiting `/demo` will grant access to the pages protected by demo mode. Of course you can choose any url you'd like.

If you want to automatically authorize certain IP addresses you can add them in the `authorized_ips` array in the `demo-mode.php` config file.

To disable the `demoAccess` route and only allow access to the `authorized_ips` you can enable `strict_mode` in the `demo-mode.php` config file.

Usage
-----

[](#usage)

You can protect some routes by using the `demoMode`-middleware on them.

```
//only users who have previously visited "/demo" will be able to see these pages.

Route::group(['middleware' => 'demoMode'], function () {
    Route::get('/secret-route', function() {
        echo 'Hi!';
    });
});
```

Unless you visit the url used by the `demoAccess` route macro first or from an authorized IP address, visiting these routes will result in a redirect in to the url specified in the `redirect_unauthorized_users_to_url`-key of the config file.

An authenticated user has access to all protected routes too.

Because it uses session to verify the user, both `demoAccess` route and protected routes must have the `web` middleware, or having the `\Illuminate\Session\Middleware\StartSession` middleware to be able to authorize a user that is either not authenticated or not visiting from an authorized IP.

Changelog
---------

[](#changelog)

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

Testing
-------

[](#testing)

```
composer test
```

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

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you've found a bug regarding security please mail  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity49

Moderate usage in the ecosystem

Community29

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 63.6% 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

Every ~113 days

Recently: every ~263 days

Total

23

Last Release

1215d ago

Major Versions

0.0.2 → 1.0.02016-03-31

v1.x-dev → 2.0.02017-08-30

PHP version history (4 changes)0.0.1PHP ^7.0

2.4.0PHP ^7.2

2.7.1PHP ^7.4|^8.0

2.7.2PHP ^8.0.2|^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (63 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (8 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (8 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (7 commits)")[![brendt](https://avatars.githubusercontent.com/u/6905297?v=4)](https://github.com/brendt "brendt (2 commits)")[![mercuryseries](https://avatars.githubusercontent.com/u/5163810?v=4)](https://github.com/mercuryseries "mercuryseries (2 commits)")[![juukie](https://avatars.githubusercontent.com/u/2678657?v=4)](https://github.com/juukie "juukie (1 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (1 commits)")[![m1guelpf](https://avatars.githubusercontent.com/u/23558090?v=4)](https://github.com/m1guelpf "m1guelpf (1 commits)")[![MarceauKa](https://avatars.githubusercontent.com/u/1665333?v=4)](https://github.com/MarceauKa "MarceauKa (1 commits)")[![m-bosch](https://avatars.githubusercontent.com/u/16580113?v=4)](https://github.com/m-bosch "m-bosch (1 commits)")[![mrk-j](https://avatars.githubusercontent.com/u/1250622?v=4)](https://github.com/mrk-j "mrk-j (1 commits)")[![dmfj](https://avatars.githubusercontent.com/u/13137236?v=4)](https://github.com/dmfj "dmfj (1 commits)")[![akoepcke](https://avatars.githubusercontent.com/u/5311185?v=4)](https://github.com/akoepcke "akoepcke (1 commits)")[![geshan](https://avatars.githubusercontent.com/u/170554?v=4)](https://github.com/geshan "geshan (1 commits)")

---

Tags

demodevelopmentlaravelmiddlewarephpspatielaravel-demo-mode

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/spatie-laravel-demo-mode/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-laravel-demo-mode/health.svg)](https://phpackages.com/packages/spatie-laravel-demo-mode)
```

###  Alternatives

[spatie/laravel-csp

Add CSP headers to the responses of a Laravel app

8569.6M19](/packages/spatie-laravel-csp)[illuminate/encryption

The Illuminate Encryption package.

9229.7M280](/packages/illuminate-encryption)[spatie/crypto

Encrypting and signing data using private/public keys

486763.5k10](/packages/spatie-crypto)[spatie/laravel-ciphersweet

Use ciphersweet in your Laravel project

416718.4k1](/packages/spatie-laravel-ciphersweet)[tzsk/otp

A secure, database-free One-Time Password (OTP) generator and verifier for PHP and Laravel.

241641.4k1](/packages/tzsk-otp)[genealabs/laravel-governor

Managing policy and control in Laravel.

201262.8k](/packages/genealabs-laravel-governor)

PHPackages © 2026

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