<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class XSSPrevent
{
    /**
     * Handle an incoming request.
     * Prevent send XSS content
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $userInput = $request->all();
        array_walk_recursive($userInput, function (&$userInput) {
            // $userInput = htmlspecialchars(strip_tags($userInput, '<p><i><span><b><strong><div><img><video><audio>'));
            $userInput = htmlspecialchars(strip_tags($userInput));
        });
        // dump($userInput);
        $request->merge($userInput);
        return $next($request);
    }
}
