mad-web / laravel-robots
Robots.txt generator service.
This package's canonical repository appears to be gone and the package has been frozen as a result.
Fund package maintenance!
mad-web
Installs: 126 895
Dependents: 1
Suggesters: 0
Security: 0
Stars: 32
Watchers: 2
Forks: 27
Open Issues: 4
Requires
- php: ^7.4 || ^8.0
- illuminate/support: ^6.0 || ^7.0 || ^8.0
Requires (Dev)
- mockery/mockery: ^1.3
- orchestra/testbench: ^4.0 || ^5.0 || ^6.0
- phpunit/phpunit: ^8.0 || ^9.3
README
Robots.txt generator service
Nice Robots.txt generator service. For more information see www.robotstxt.org
Installation
You can install the package via composer:
composer require mad-web/laravel-robots
Usage
Setting a condition in your AppServiceProvider
that determines whether the site should be indexed.
use MadWeb\Robots\RobotsFacade; public function boot() { RobotsFacade::setShouldIndexCallback(function () { return app()->environment('production'); }); ... }
You can create simple single action controller for generating robots.txt
/routes/web.php
Route::get('robots.txt', 'RobotsController');
/app/Http/Controllers/Robots
namespace App\Http\Controllers; use MadWeb\Robots\Robots; use App\Http\Controllers\Controller; class RobotsController extends Controller { /** * Generate robots.txt */ public function __invoke(Robots $robots) { $robots->addUserAgent('*'); if ($robots->shouldIndex()) { // If on the live server, serve a nice, welcoming robots.txt. $robots->addDisallow('/admin'); $robots->addSitemap('sitemap.xml'); } else { // If you're on any other server, tell everyone to go away. $robots->addDisallow('/'); } return response($robots->generate(), 200, ['Content-Type' => 'text/plain']); } }
Add robots meta tag into your view inside the <head>
tag
<head> {!! Robots::metaTag() !!} </head>
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
composer test
Contributing
Please see CONTRIBUTING and CONDUCT for details.
Security
If you discover any security related issues, please email madweb.dev@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.