1. The existing code is implemented as follows
"url": "{{ json_encode($item['url_object']) }}",
2. The final generated JSON data structure is as follows:
"url": "{"ID":18,"title":"summer","object":"product_cat","object_id":18,"children":[],"url":"/collections/summer","key":3991}",
3. The Blade {{ }} statement is automatically passed through PHP’s HtmlSpecialChars function to prevent XSS attacks. Therefore, you need {!! !!} to prevent the “(double quotes) from being converted into HTML entities.
"url": "{!! htmlspecialchars(json_encode($item['url_object']), ENT_NOQUOTES | ENT_HTML401) !!}",
4. However, the generated JSON structure is wrong. The reason is that the value of the URL is not escaped. as shown in Figure 1

{
"image": "",
"mobile_image": "",
"url": "{"ID":18,"title":"summer","object":"product_cat","object_id":18,"children":[],"url":"\/collections\/summer","key":3991}",
"title": "summer"
}
5. Use addcslashes — Use the characters in the backslash to escape the characters in C style.
"url": "{!! htmlspecialchars(addcslashes(json_encode($item['url_object']), "\f\n\r\t\\\""), ENT_NOQUOTES | ENT_HTML401) !!}",
6. The generated JSON structure is correct. as shown in Figure 2

{
"url": "{\"ID\":18,\"title\":\"summer\",\"object\":\"product_cat\",\"object_id\":18,\"children\":[],\"url\":\"\\/collections\\/summer\",\"key\":3991}",
"image": "",
"title": "summer",
"mobile_image": ""
}
PHP / Laravel / Yii2 Legacy Project Maintenance & Long-Term Technical Support
If your PHP / Laravel / Yii2 project is already in production but needs bug fixing, API troubleshooting, performance optimization, developer handover support, or long-term maintenance, feel free to contact me for remote technical support.
Ideal For:
✅ PHP legacy systems without active maintenance
✅ Laravel / Yii2 project bug fixes
✅ Admin panel feature iterations
✅ RESTful API troubleshooting
✅ MySQL / Redis / Nginx performance issues
✅ Long-term remote part-time maintenance
We can start with a small task:
✅ Production error troubleshooting
✅ API issue analysis
✅ Slow query and performance bottleneck diagnosis
✅ Initial code structure review
✅ Deployment environment and log inspection
If you would like to discuss your project, please contact me and mention: PHP Maintenance Consultation.
Contact Me:
Telegram: @shuijingwan
WeChat: 13980074657
Email: shuijingwanwq@gmail.com

Leave a Reply