PHP code example of mtconsultingroup / laravel-robots
1. Go to this page and download the library: Download mtconsultingroup/laravel-robots library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mtconsultingroup / laravel-robots example snippets
use MadWeb\Robots\RobotsFacade;
public function boot()
{
RobotsFacade::setShouldIndexCallback(function () {
return app()->environment('production');
});
...
}
Route::get('robots.txt', 'RobotsController');
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']);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.