select data with escaped output

Published 1 year 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.


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

you can set it in an accessor.

1 year ago (14,235 XP)

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


here are the hints ..

for htmlentities()

for eloquent accessor

or you can also use strip_tags() function to remove html tags.

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