{"id":19074926,"url":"https://github.com/mguinea/laravel-robots","last_synced_at":"2025-04-29T16:27:37.133Z","repository":{"id":47775897,"uuid":"143919791","full_name":"mguinea/laravel-robots","owner":"mguinea","description":"Laravel package to manage robots","archived":false,"fork":false,"pushed_at":"2025-04-15T05:04:07.000Z","size":537,"stargazers_count":16,"open_issues_count":6,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T06:20:12.064Z","etag":null,"topics":["laravel","package","robots","robots-txt","seo","seotools"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mguinea.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-07T19:47:18.000Z","updated_at":"2025-04-15T05:04:11.000Z","dependencies_parsed_at":"2024-10-25T15:15:23.960Z","dependency_job_id":"7aae3028-819f-4079-affa-bad60a8417fa","html_url":"https://github.com/mguinea/laravel-robots","commit_stats":{"total_commits":79,"total_committers":7,"mean_commits":"11.285714285714286","dds":"0.44303797468354433","last_synced_commit":"0ced0c772b5dd9ae113de53d56dd90aed4728a2c"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mguinea%2Flaravel-robots","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mguinea%2Flaravel-robots/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mguinea%2Flaravel-robots/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mguinea%2Flaravel-robots/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mguinea","download_url":"https://codeload.github.com/mguinea/laravel-robots/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251538972,"owners_count":21605619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","package","robots","robots-txt","seo","seotools"],"created_at":"2024-11-09T01:52:49.184Z","updated_at":"2025-04-29T16:27:37.086Z","avatar_url":"https://github.com/mguinea.png","language":"PHP","funding_links":["https://www.buymeacoffee.com/mguinea"],"categories":[],"sub_categories":[],"readme":"# Laravel Robots\n\nLaravel package to manage robots easily.\n\nIf you need a detailed explanation about how robots.txt file works, visit http://www.robotstxt.org/robotstxt.html\n\n\u003cdiv style=\"text-align: center;\"\u003e\u003ca href=\"https://www.buymeacoffee.com/mguinea\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/default-orange.png\" alt=\"Buy Me A Coffee\" height=\"41\" width=\"174\"\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cdiv style=\"text-align: center;\"\u003e\n\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mguinea/laravel-robots/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mguinea/laravel-robots/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/mguinea/laravel-robots/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/mguinea/laravel-robots/?branch=master)\n[![Build Status](https://scrutinizer-ci.com/g/mguinea/laravel-robots/badges/build.png?b=master)](https://scrutinizer-ci.com/g/mguinea/laravel-robots/build-status/master)\n[![StyleCI](https://styleci.io/repos/143919791/shield?branch=master)](https://styleci.io/repos/143919791)\n[![License MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Laravel](https://img.shields.io/badge/Laravel-8-orange.svg)](http://laravel.com)\n\n\u003c/div\u003e\n\nThis package allows you to manage robots of your site dinamically allowing you to differenciate between environments or configurations.\n\nMigration to persist configuration is optional; you can change its data source.\n\nOnce package is installed you can do these things:\n\n```php\nRoute::get('robots.txt', function() {\n    $robots = new \\Mguinea\\Robots\\Robots;\n\n    // If on the live server\n    if (App::environment() == 'production') {\n        $robots-\u003eaddUserAgent('*')-\u003eaddSitemap('sitemap.xml');\n    } else {\n        // If you're on any other server, tell everyone to go away.\n        $robots-\u003eaddDisallow(\"/\");\n    }\n\n    return response($robots-\u003egenerate(), 200)-\u003eheader('Content-Type', 'text/plain');\n});\n``` \n\n### Installing\n\nYou can install via Composer.\n\n```bash\ncomposer require mguinea/laravel-robots\n```\n\n## Running the tests\n\nJust execute\n\n```bash\nvendor/bin/phpunit\n```\n\nUnit tests will test all methods from Robots class and its related facade.\n\n## Usage\n\n### 1. Dynamically\n\nYou can use Robots in routes file to generate a dynamic response\n\n```php\nRoute::get('robots.txt', function() {\n    $robots = new \\Mguinea\\Robots\\Robots;\n\n    // If on the live server\n    if (App::environment() == 'production') {\n        $robots-\u003eaddUserAgent('*')-\u003eaddSitemap('sitemap.xml');\n    } else {\n        // If you're on any other server, tell everyone to go away.\n        $robots-\u003eaddDisallow(\"/\");\n    }\n\n    return response($robots-\u003egenerate(), 200)-\u003eheader('Content-Type', 'text/plain');\n});\n```\n\n### 1.1. Dynamically with facade\n\nYou can use Robots facade in routes file to generate a dynamic response\n\n```php\n\u003c?php\n\nuse Mguinea\\Robots\\Facades\\Robots;\n\nRoute::get('robots.txt', function() {\n\n    // If on the live server\n    if (App::environment() == 'production') {\n        Robots::addUserAgent('*');\n        Robots::addSitemap('sitemap.xml');\n    } else {\n        // If you're on any other server, tell everyone to go away.\n        Robots::addDisallow(\"/\");\n    }\n\n    return response(Robots::generate(), 200)-\u003eheader('Content-Type', 'text/plain');\n});\n```\n\n### 2. To robots.txt default file\n\nIf you prefer to write the original robots.txt file, just use the generator as you have seen\n\n```php\n\u003c?php\n\nuse Illuminate\\Http\\File;\nuse Mguinea\\Robots\\Robots;\n\nclass Anywhere\n{\n    public function createFile()\n    {\n        $robots = new Robots;\n        $robots-\u003eaddUserAgent('*')-\u003eaddSitemap('sitemap.xml');\n\n        File::put(public_path('robots.txt'), $robots-\u003egenerate());\n    }\n}\n\n```\n\n### 3. Building from Data Source\n\nYou could prefer building it from some data source. To get that, you just must instantiate Robots object using an array with key value parameters as shown below.\n\nNote that comments and spacers have been removed.\n\n```php\n\u003c?php\n\nuse Illuminate\\Http\\File;\nuse Mguinea\\Robots\\Robots;\n\nclass Anywhere\n{\n    public function fromArray()\n    {\n        $robots = new Robots([\n            'allows' =\u003e [\n                'foo', 'bar'\n            ],\n            'disallows' =\u003e [\n                'foo', 'bar'\n            ],\n            'hosts' =\u003e [\n                'foo', 'bar'\n            ],\n            'sitemaps' =\u003e [\n                'foo', 'bar'\n            ],\n            'userAgents' =\u003e [\n                'foo', 'bar'\n            ],\n            'crawlDelay' =\u003e 10\n        ]);\n        \n        return response($robots-\u003egenerate(), 200)-\u003eheader('Content-Type', 'text/plain');\n    }\n}\n\n```\n\n### Methods\n\nYou can use Robots class methods in an individual or nested way.\n\nRemember that you can use Facade to avoid instantiation.\n\n```php\n\u003c?php\n    // Add an allow rule to the robots. Allow: foo\n    $robots-\u003eaddAllow('foo');\n\n    // Add multiple allows rules to the robots. Allow: foo Allow: bar\n    $robots-\u003eaddAllow(['foo', 'bar']);\n```\n\n```php\n\u003c?php\n    // Add a comment to the robots. # foo\n    $robots-\u003eaddComment('foo');\n```\n\n```php\n\u003c?php\n    // Add a disallow rule to the robots. Disallow: foo\n    $robots-\u003eaddDisallow('foo');\n\n    // Add multiple disallows rules to the robots. Disallow: foo Disallow: bar\n    $robots-\u003eaddDisallow(['foo', 'bar']);\n```\n\n```php\n\u003c?php\n    // Add a Host to the robots. Host: foo\n    $robots-\u003eaddHost('foo');\n    \n    // Add multiple hosts to the robots. Host: foo Host: bar\n    $robots-\u003eaddHost(['foo', 'bar']);\n```\n\n```php\n\u003c?php\n    // Add a Sitemap to the robots. Sitemap: foo\n    $robots-\u003eaddSitemap('foo');\n    \n    // Add multiple sitemaps to the robots. Sitemap: foo Sitemap: bar\n    $robots-\u003eaddSitemap(['foo', 'bar']);\n```\n\n```php\n\u003c?php\n    // Add a spacer to the robots.\n    $robots-\u003eaddSpacer();\n```\n\n```php\n\u003c?php\n    // Add a User-agent to the robots. User-agent: foo\n    $robots-\u003eaddUserAgent('foo');\n    \n    // Add multiple User-agents to the robots. User-agent: foo User-agent: bar\n    $robots-\u003eaddUserAgent(['foo', 'bar']);\n```\n\n```php\n\u003c?php\n    // Add a crawl-delay to the robots. crawl-delay: 10\n    $robots-\u003eaddCrawlDelay(10);\n```\n\n```php\n\u003c?php\n    // Generate the robots data.\n    $robots-\u003egenerate();\n```\n\n```php\n\u003c?php\n    // Reset the rows.\n    $robots-\u003ereset();\n```\n\n## Built With\n\n* [Laravel](https://laravel.com/) - The web framework\n* [Composer](https://getcomposer.org/) - Dependency manager\n\n## Contributing\n\nPlease read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests.\n\n## Security\n\nIf you discover any security related issues, please email develop.marcguinea@gmail.com instead of using the issue tracker.\n\n## Versioning\n\nWe use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/mguinea/laravel-robots/tags).\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE.md) file for details\n\n## Authors\n\n* **Marc Guinea** [MarcGuinea](https://www.marcguinea.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmguinea%2Flaravel-robots","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmguinea%2Flaravel-robots","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmguinea%2Flaravel-robots/lists"}