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?
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.
via Chebli Mohamed
 
Aucun commentaire:
Enregistrer un commentaire