october middleware bot spider google
<?php
namespace Develex\AbStatistics\Classes\Http;
use Closure;
use Illuminate\Http\Request;
class BotsMiddleware {
/**
* Filter request from spiders and bots by User-Agent
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
if(preg_match('/bot|crawl|slurp|spider/i', $request->header('user-agent', ''))){
return '';
}
return $next($request);
}
}
На группу маршрутов
Route::group(['middleware' => 'Develex\AbStatistics\Classes\Http\BotsMiddleware'], function(){
Route::get('log', ['uses' => 'Develex\AbStatistics\Controllers\StatisticsController@log']);
});
В plugin.php в boot
// Add a new middleware to beginning of the stack.
$this->app['Illuminate\Contracts\Http\Kernel']
->prependMiddleware('Path\To\Custom\Middleware');
// Add a new middleware to end of the stack.
$this->app['Illuminate\Contracts\Http\Kernel']
->pushMiddleware('Path\To\Custom\Middleware');
Или так
Cms\Classes\CmsController::extend(function($controller) {
$controller->middleware('your middleware here');
});