-1

I am trying to add newrelic to my laravel site. I found this repo. But couldn't use it properly.

Where should I put this code?

App::after( function() {
    Newrelic::setAppName( 'MyApp' );
} );

Or maybe other ways to add routes response time to newrelic...

Maxim Yefremov
  • 13,671
  • 27
  • 117
  • 166

1 Answers1

2

App::after does not exists anymore.

You can register a middleware that is executed after the request to do what you need:

<?php

namespace App\Http\Middleware;

use Closure;

class AfterMiddleware
{
    public function handle($request, Closure $next)
    {
        $response = $next($request);

        Newrelic::setAppName( 'MyApp' );

        return $response;
    }
}

and register it as usually in app/Http/Kernel.php:

 protected $middleware = [
        ...,
        \App\Http\Middleware\AfterMiddleware::class
    ];
oltreseba
  • 142
  • 9
  • Did you get this to work Maxim? I do not get the downvote. Leave a comment if you got it to work and I'll vote. – Ususipse Oct 10 '19 at 23:30