Blog

Method 1. Reponse Macro

app/Providers/AppServiceProvider.php:

Response::macro('json_escape', function ($aData) {
    array_walk_recursive($aData, function (&$v, $k) {
        $v = strip_tags($v);
    });
    return Response::json($aData);
});

Usage:

return response()->json_escape($aData)

Method 2. Helper Function

composer.json:

"autoload": {
    "files": [
        "app/helpers.php"
    ]
},

app/helpers.php:

use Illuminate\Support\Facades\Response;

function json_escape($aData) {
    array_walk_recursive($aData, function (&$v, $k) {
        $v = strip_tags($v);
    });

    return Response::json($aData);
}

Usage:

return json_escape($aData);
Zoeken