select data with escaped output

Published 8 months ago by lorvent

Hello, i have query like this

$data = Model::all();

the problem is, one row has code like <script>alert('boom')</script>

so instead of executing javascript code, i want to escape the data.

is there any such option available with eloquent?

Note: this data is being sent through ajax so i can't use blade escape feature.

bunnypro

you can use php built-in function htmlentities().

you can set it in an accessor.

lorvent

Thanks for the reply @bunnypro can you please give some hint on it?

bunnypro

here are the hints ..

for htmlentities() https://www.w3schools.com/php/func_string_htmlentities.asp

for eloquent accessor https://laravel.com/docs/5.4/eloquent-mutators#defining-an-accessor

or you can also use strip_tags() function to remove html tags. https://www.w3schools.com/php/func_string_strip_tags.asp

Please sign in or create an account to participate in this conversation.