PHPackages                             mguinea/laravel-robots - 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. mguinea/laravel-robots

ActiveLaravel-package

mguinea/laravel-robots
======================

Laravel package to manage robots in an easy way

3.1.4(1y ago)1659.7k—2.7%4[6 PRs](https://github.com/mguinea/laravel-robots/pulls)MITPHPPHP &gt;=8.1CI failing

Since Aug 7Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/mguinea/laravel-robots)[ Packagist](https://packagist.org/packages/mguinea/laravel-robots)[ Docs](https://github.com/mguinea/laravel-robots)[ RSS](/packages/mguinea-laravel-robots/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (29)Used By (0)

Laravel Robots
==============

[](#laravel-robots)

Laravel package to manage robots easily.

If you need a detailed explanation about how robots.txt file works, visit

[![Buy Me A Coffee](https://camo.githubusercontent.com/9a769e616ce78645bf51d12e4179cfbfd72fb413722b284e0be3ec3c75a86010/68747470733a2f2f63646e2e6275796d6561636f666665652e636f6d2f627574746f6e732f64656661756c742d6f72616e67652e706e67)](https://www.buymeacoffee.com/mguinea)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/e6f7c5f18ee0c791a799aaa45b54a555494806449b7e04a359b0acf4190db064/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6775696e65612f6c61726176656c2d726f626f74732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mguinea/laravel-robots/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/97f88168a7f9fc8d2168f7673dbe763c19a3e552835f38585d93398ecf219e68/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6775696e65612f6c61726176656c2d726f626f74732f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mguinea/laravel-robots/?branch=master)[![Build Status](https://camo.githubusercontent.com/4129055f8cafe7aaa27598e9175db96a072a6a20e58fdff2ed805f80de351f34/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6775696e65612f6c61726176656c2d726f626f74732f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mguinea/laravel-robots/build-status/master)[![StyleCI](https://camo.githubusercontent.com/e95fe787174dd42891658922962003eebd08cc30fa2e7d6b7c2d7e98ff38f36c/68747470733a2f2f7374796c6563692e696f2f7265706f732f3134333931393739312f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/143919791)[![License MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![Laravel](https://camo.githubusercontent.com/0a3e81023a09a27c94365c2daaceeb78ecbb6ea24a294c212ed9d9780e2ee542/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d382d6f72616e67652e737667)](http://laravel.com)

This package allows you to manage robots of your site dinamically allowing you to differenciate between environments or configurations.

Migration to persist configuration is optional; you can change its data source.

Once package is installed you can do these things:

```
Route::get('robots.txt', function() {
    $robots = new \Mguinea\Robots\Robots;

    // If on the live server
    if (App::environment() == 'production') {
        $robots->addUserAgent('*')->addSitemap('sitemap.xml');
    } else {
        // If you're on any other server, tell everyone to go away.
        $robots->addDisallow("/");
    }

    return response($robots->generate(), 200)->header('Content-Type', 'text/plain');
});
```

### Installing

[](#installing)

You can install via Composer.

```
composer require mguinea/laravel-robots
```

Running the tests
-----------------

[](#running-the-tests)

Just execute

```
vendor/bin/phpunit
```

Unit tests will test all methods from Robots class and its related facade.

Usage
-----

[](#usage)

### 1. Dynamically

[](#1-dynamically)

You can use Robots in routes file to generate a dynamic response

```
Route::get('robots.txt', function() {
    $robots = new \Mguinea\Robots\Robots;

    // If on the live server
    if (App::environment() == 'production') {
        $robots->addUserAgent('*')->addSitemap('sitemap.xml');
    } else {
        // If you're on any other server, tell everyone to go away.
        $robots->addDisallow("/");
    }

    return response($robots->generate(), 200)->header('Content-Type', 'text/plain');
});
```

### 1.1. Dynamically with facade

[](#11-dynamically-with-facade)

You can use Robots facade in routes file to generate a dynamic response

```
