According to the Laravel
convention, the getShortProdNameAttribute()
mutator will resolve to the short_prod_name
attribute:
$item->short_prod_name
Rememeber to append the additional attribute in the Item
class:
protected $appends = ['short_prod_name']
Thusly, the full code snippet is as follows:
@foreach($order->cart->items as $item)
<tr>
<th scope="row"><a href="/{{ $item['code_cat'] }}/{{ $item['url_cat'] }}/{{ $item['prod_url'] }}"><img class="basketimg mr-1" src="/img/products/{{$item['img']}}"><span class="basket-prod-name">{{ $item->short_prod_name }}</span></a></th>
<td class="text-center">
<div class="prodcount">{{$item['qty']}}</div>
</td>
<td class="text-right">{{$item['cost']}}AZN</td>
</tr>
@endforeach
An alternative solution to address our problem is to use Str::limit
:
@foreach($order->cart->items as $item)
<tr>
<th scope="row"><a href="/{{ $item['code_cat'] }}/{{ $item['url_cat'] }}/{{ $item['prod_url'] }}"><img class="basketimg mr-1" src="/img/products/{{$item['img']}}"><span class="basket-prod-name">{{ Str::limit($item->name, 10) }}</span></a></th>
<td class="text-center">
<div class="prodcount">{{$item['qty']}}</div>
</td>
<td class="text-right">{{$item['cost']}}AZN</td>
</tr>
@endforeach
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…