spatie / laravel-robots-middleware by spatie

Add an `all` or `none` robots header to your requests via a middleware in Laravel
Package Data
Maintainer Username: spatie
Maintainer Contact: (Sebastian De Deyne)
Package Create Date: 2016-01-04
Package Last Update: 2023-06-30
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-02-25 15:28:04
Package Statistics
Total Downloads: 1,259,142
Monthly Downloads: 30,245
Daily Downloads: 206
Total Stars: 315
Total Watchers: 6
Total Forks: 33
Total Open Issues: 0

Enable or disable the indexing of your app

Latest Version on Packagist Software License Build Status SensioLabsInsight Quality Score StyleCI Total Downloads

A tiny, opinionated package to enable or disable indexing your site via a middleware in Laravel.

More on the Robots meta tag:

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.


You can install the package via composer:

$ composer require spatie/laravel-robots-middleware


By default, the middleware enables indexing on all pages. You'll probably want to inherit your own class containing you application's indexing rule handler.

// app/Http/Middleware/MyRobotsMiddleware.php

use Illuminate\Http\Request;
use Spatie\RobotsMiddleware\RobotsMiddleware;

class MyRobotsMiddleware extends RobotsMiddleware
     * @return string|bool
    protected function shouldIndex(Request $request)
        return $request->segment(1) !== 'admin';

Next, simply register the newly created class in your middleware stack.

// app/Http/Kernel.php

class Kernel extends HttpKernel
    protected $middleware = [
        // ...
    // ...

That's it! Responses will now always have an x-robots-tag in their headers, containing an all or none value.


Please see CHANGELOG for more information what has changed recently.


$ composer test


Please see CONTRIBUTING for details. Due to nature of this package, there's a fair chance features won't be accepted to keep it light and opinionated.


If you discover any security related issues, please email instead of using the issue tracker.


You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.

We publish all received postcards on our company website.


Support us

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.


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