Configure indexing rules by extending RobotsMiddleware
mainBy default, the middleware enables indexing on all pages. To implement custom logic, create a new middleware class that extends Spatie\RobotsMiddleware\RobotsMiddleware and implement the shouldIndex method.
The shouldIndex method must return either a string or a bool. If it returns true (or a truthy value), the response will include an x-robots-tag: all header. If it returns false (or a falsy value), the response will include an x-robots-tag: none header.
// 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)
{
// Example: Do not index any routes starting with 'admin'
return $request->segment(1) !== 'admin';
}
}