Nice Robots.txt generator service. For more information see www.robotstxt.org
You can install the package via composer:
composer require mad-web/laravel-robots
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>
Please see CHANGELOG for more information what has changed recently.
$ composer test
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.