Level 21
I'm not following your question exactly, but it sounds like you might want to use Laravel's e helper:
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
PHP 7, working with UTF-8
$model = new Model();
$model->text = "This quo'<script>alert('omg')</script>";
$model->save();
Good!
In DB, the field is:
This quo'<script>alert('omg')</script>
Good!
On a view
{{$model->text}}
And says:
This quo'<script>alert('omg')</script>
Good!
But when working with AJAX and returning the string from database, doing the "echo", appears the "omg" alert on browser. So, my question is, which is the best way to handle this?
I know there's no "best" but right now I have escaped the string with htmlspecialchars(), any other more productive or "laravel" way to do this?
I'm not following your question exactly, but it sounds like you might want to use Laravel's e helper:
Please or to participate in this conversation.