Laravel清理中间件无法正常工作

I'm using a sanitizing package. this package is for laravel and sanitizes data for security and XSS attacks and has a helper function: clean($data) , $data can be a string or array.

I build a middleware to purify data for every requet that is comming.

handle() function for this middleware is:

    public function handle( $request, Closure $next)
    {
        $request = clean( $request->all() );

        return $next( $request );
    }

this function cleans and purifies every data thai is comming to my app.

I know I'm making a big mistake and misunderstanding!

what I have done wrong?

Your clean() function should return an instance of Illuminate\Http\Request because that's what the $next Closure needs to proceed. Perhaps your clean() function is returning a different type such as a string or an array.