May I know which is the best practice for encoding HTML texts and decode HTML texts when display content?
Should I handle it at the controller before to blade or handle it at the blade view? If I handle it at blade view, should I include e($text) to escape?
May I know which one Is the correct example below?
Example 1:
Controller.php
htmlspecialchars($text) //To encode and store into db
htmlspecialchars_decode($text) // to decode and display text to blade view
blade
<p> {!! nl2br($text) !!}</p>
Example 2:
Controller.php
htmlspecialchars($text) //To encode and store into db
blade
<p> {!! htmlspecialchars_decode(nl2br($text)) !!}</p>
Example 3:
Controller.php
htmlspecialchars($text) //To encode and store into db
htmlspecialchars_decode($text) // to decode and display text to blade view
blade
<p> {!! htmlspecialchars_decode(nl2br(e($text))) !!}</p>
Example 4:
Controller.php
htmlspecialchars($text) //To encode and store into db
blade
<p> {!! htmlspecialchars_decode(nl2br($text)) !!}</p>