https://github.com/spatie/laravel-robots-middleware
Enable or disable the indexing of your app
https://github.com/spatie/laravel-robots-middleware
google laravel php robots seo
Last synced: 17 days ago
JSON representation
Enable or disable the indexing of your app
- Host: GitHub
- URL: https://github.com/spatie/laravel-robots-middleware
- Owner: spatie
- License: mit
- Created: 2016-01-04T19:24:34.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2025-02-21T14:12:56.000Z (2 months ago)
- Last Synced: 2025-04-06T08:02:38.696Z (24 days ago)
- Topics: google, laravel, php, robots, seo
- Language: PHP
- Homepage: https://freek.dev/350-say-goodbye-to-manually-creating-a-robotstxt-file
- Size: 72.3 KB
- Stars: 331
- Watchers: 5
- Forks: 33
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# Enable or disable the indexing of your app
[](https://packagist.org/packages/spatie/laravel-robots-middleware)
[](https://github.com/spatie/laravel-robots-middleware/actions/workflows/run-tests.yml)

[](https://packagist.org/packages/spatie/laravel-robots-middleware)A tiny, opinionated package to enable or disable indexing your site via a middleware in Laravel.
More on the Robots meta tag: https://developers.google.com/webmasters/control-crawl-index/docs/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](https://spatie.be/opensource).
## Support us
[
](https://spatie.be/github-ad-click/laravel-robots-middleware)
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
You can install the package via composer:
``` bash
$ composer require spatie/laravel-robots-middleware
```## Usage
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.
```php
// app/Http/Middleware/MyRobotsMiddleware.php
namespace App\Http\Middleware;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.
```php
// app/Http/Kernel.phpclass Kernel extends HttpKernel
{
protected $middleware = [
// ...
\App\Http\Middleware\MyRobotsMiddleware::class,
];
// ...
}
```That's it! Responses will now always have an `x-robots-tag` in their headers, containing an `all` or `none` value.
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
## Testing
``` bash
$ composer test
```## Contributing
Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details. Due to nature of this package, there's a fair chance features won't be accepted to keep it light and opinionated.
## Security
If you've found a bug regarding security please mail [[email protected]](mailto:[email protected]) instead of using the issue tracker.
## Credits
- [Sebastian De Deyne](https://github.com/sebastiandedeyne)
- [All Contributors](../../contributors)## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.