mtconsultingroup/laravel-robots

Robots.txt generator service.
4,803
Install
composer require mtconsultingroup/laravel-robots
Latest Version:2.1.2
PHP:^7.2.5 || ^8.0
License:MIT
Last Updated:Feb 21, 2022
Links: GitHub  ·  Packagist
Maintainer: tosettil

Robots.txt generator service

Latest Version on Packagist Software License Build Status StyleCI Coverage Status Quality Score Total Downloads

Nice Robots.txt generator service. For more information see www.robotstxt.org

Installation

You can install the package via composer:

composer require mtconsultingroup/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.

Related Packages

mad-web/laravel-seoable

Easy to map your eloquent fields to seo properties

7,552 40
particle-academy/fancy-seo

Server-rendered SEO + crawlability for Laravel + Inertia apps — per-route meta/O...

739 1
spatie/laravel-robots-middleware

Add an `all` or `none` robots header to your requests via a middleware in Larave...

2,394,887 334
calotype/seo

A package containing SEO helpers.

2,642 73
programmerhasan/seo

Lightweight, modern SEO toolkit for Laravel, Inertia, Schema.org, sitemaps, robo...

9 2