PHP code example of spatie / laravel-robots-middleware
1. Go to this page and download the library: Download spatie/laravel-robots-middleware 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/ */
spatie / laravel-robots-middleware example snippets
// app/Http/Middleware/MyRobotsMiddleware.php
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Spatie\RobotsMiddleware\RobotsMiddleware;
class MyRobotsMiddleware extends RobotsMiddleware
{
/**
* @return string|bool
*/
protected function shouldIndex(Request $request)
{
return $request->segment(1) !== 'admin';
}
}
// app/Http/Kernel.php
class Kernel extends HttpKernel
{
protected $middleware = [
// ...
\App\Http\Middleware\MyRobotsMiddleware::class,
];
// ...
}