jeudi 31 août 2017

Cannot set content with Laravel middleware

I'm trying to append some query log data to my ajax requests via a middelware.

use DB;
use App;
use Closure;

class Queries
{
    public function handle($request, Closure $next)
    {
        if (env('APP_QUERIES')) {
            DB::enableQueryLog();

            $response = $next($request);

            $content_type = substr($response->headers->get('Content-Type'), 0, 16);

            if ($content_type === 'application/json') {
                $content = $response->original;

                $queries = DB::getQueryLog();

                $content['queries'] = $queries;

                $response->setContent($content);
            }

            return $response;
        }

        return $next($request);
    }
}

In the docs it shows $mixed but seems it only excepts string?

http://ift.tt/2ensX6J

When I put json_encode around the $content it works, but in another app I don't have this and it's the same version of Laravel so not sure what's going on.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2iKpd4b
via IFTTT

Aucun commentaire:

Enregistrer un commentaire