@forelse($orders as $order)
<tr class="dropdown sliderow" data-toggle="collapse" data-target="#{{$order->id}}" data-parent="#myAccordion">
<td >{{$order->id}}</td>
<td>{{$order->customer_name}}</td>
<td>{{$order->customer_email}}</td>
<td>{{$order->customer_contact}}</td>
<td>{{$order->customer_address}}</td>
<td>
<div class="action-box">
<a href=""><i class="fa fa-angle-down">Details</i></a>
{{--<a href=""><i class="fa fa-remove"></i></a>--}}
</div>
</td>
<tr >
<td colspan="6">
<div class="container-fluid collapse" id="{{$order->id}}" style="position:relative;">
<div class="row">
<div class="col-sm-6">
<h2>Customer info </h2>
<b>Name</b> <span>{{$order->customer_name}}</span><br>
<b>Phone</b> <span>{{$order->customer_contact}}</span><br>
<b>Address</b> <span>{{$order->customer_address}}</span><br>
<h2>Products</h2>
<table cellpadding="1" class="table table-sm table-hover table-responsive">
<tr>
<th>name</th>
<th>quantity</th>
<th>total price</th>
</tr>
<tr>
<td>{{$order->product_names}}</td>
<td>{{$order->products_quantity}}</td>
<td>PKR 70,000</td>
</tr>
</table>
</div>
<div class="col-sm-6">
<h4>order status</h4>
<select name="delivery_status" id="" class="form-control">
<option value="status" selected>status</option>
<option value="not-deliverd">shipped</option>
<option value="delivered">shipped and received by customer</option>
</select>
</div>
</div>
</div></td></tr></tr>
</div>
@empty
<tr class="text-center warning">
<td colspan="6">No Record Found</td>
</tr>
@endforelse
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
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
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/>:
<td>{!! str_replace("," "<br/>", $order->product_names) !!}</td>
Note: You have to use {!! !!}
{!! !!}
instead of {{ }}
so it outputs the HTML properly.
first you have to add <br/>
tag into your data. find the length of your data and add \n
at specific point.
$length=strlen($order->product_names);
if($length>50){
$order->product_names = substr_replace($order->product_names," \n" ,
position, 0);
}
after that only just write your table cell just like below:
<td>{!! nl2br($order->product_names) !!}</td>
you have to just write {!! !!}
{!! !!}
rather then {{ }}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.