Skip to content
Advertisement

adding line break in string data coming from database in laravel

JavaScript

here the above code is my orders display code I want to add line breaks in product_name which is the string
and showing like Hp I7 8th generation, Huawei p30 pro
I want to break the line and add the second product which is after the comma in the next row of the table

here is the image of how my products of the order are showing
here is the image of how my products of the order are showing

Am I wrong in storing products in the database because I add customers product in the array and then convert it into the string for storing in database I now they are retrieving like this as shown in image

Advertisement

Answer

First of all, storing product_names as a string goes against RDBMS principles; each product should be an entry in a separate table (products), linked to the order (orders) via some other method (generally a pivot table for orders and products, orders_products).

There is a simple way to display these, simply replace , in the string with <br/>:

JavaScript

Note: You have to use {!! !!} instead of {{ }} so it outputs the HTML properly.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement