PHP code example of fuelviews / laravel-robots-txt
1. Go to this page and download the library: Download fuelviews/laravel-robots-txt 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/ */
fuelviews / laravel-robots-txt example snippets
return [
/**
* The disk where the robots.txt file will be saved
*/
'disk' => 'public',
/**
* User agent rules for different paths
*/
'user_agents' => [
'*' => [
'Allow' => [
'/',
],
'Disallow' => [
'/admin',
'/dashboard',
],
],
'Googlebot' => [
'Allow' => [
'/',
],
'Disallow' => [
'/admin',
],
],
],
/**
* Sitemaps to
use Fuelviews\RobotsTxt\Facades\RobotsTxt;
// Get robots.txt content
$content = RobotsTxt::getContent();
// Generate fresh content (bypasses cache)
$content = RobotsTxt::generate();
// Save to a specific disk and path
RobotsTxt::saveToFile('s3', 'seo/robots.txt');
use Fuelviews\RobotsTxt\RobotsTxt;
$robotsTxt = app(RobotsTxt::class);
// Check if regeneration is needed
$content = $robotsTxt->getContent();
// Generate and save to custom location
$robotsTxt->saveToFile('public', 'custom-robots.txt');
// In your views
<link rel="robots" href="{{ route('robots') }}">
// Generate URL
$robotsUrl = route('robots');
use Illuminate\Support\Facades\Cache;
// Clear the robots.txt cache
Cache::forget('robots-txt.checksum');
use Fuelviews\RobotsTxt\Facades\RobotsTxt;
// Save to specific location
RobotsTxt::saveToFile('s3', 'seo/robots.txt');
// Save to multiple locations
RobotsTxt::saveToFile('public', 'robots.txt');
RobotsTxt::saveToFile('backup', 'robots-backup.txt');