bakiro/laravel-5-robots

Laravel 5 机器人.txt 生成器

0.1.0 2020-04-23 17:40 UTC

This package is auto-updated.

Last update: 2024-09-24 04:45:33 UTC


README

这是一个 https://github.com/jayhealey/Robots 的分支。原始仓库的开发似乎已经停止。

这个分支的目的是引入 Laravel 5 兼容性和 PSR-4 以及 PSR-2(对于 Laravel 5.1)。

安装

步骤 1: Composer

将包添加到您的 composer.json

{
    "require": {
        "bakiro/laravel-5-robots": "~0.1.0"
    }
}

步骤 2: 配置

将以下内容添加到您的 config/app.php 中的 providers 数组

'Bakiro\Robots\RobotsServiceProvider',

您也可以选择性地将以下内容添加到 aliases 数组

'Robots' => 'Bakiro\Robots\RobotsFacade',

使用方法

将以下内容添加到您的路由文件

Route::get('robots.txt', function ()
{
    if (App::environment() == 'production') {
        // If on the live server, serve a nice, welcoming robots.txt.
        Robots::addUserAgent('*');
        Robots::addSitemap('sitemap.xml');
    } else {
        // If you're on any other server, tell everyone to go away.
        Robots::addDisallow('*');
    }

    return Response::make(Robots::generate(), 200, ['Content-Type' => 'text/plain']);
});

有关 API 使用方法,请参考 Robots.php

许可证

MIT