How do i add a span tag around the $product->category->name in one line?
<td>{{$product->category ? $product->category->name : 'category not known'}}</td>
<span >{{$product->category->name}}</span><br>
CodePudding user response:
In your comment you have a blade echo in your blade echo, just remove that one and add '( ... )':
<td>{!! $product->category ? ('<span >' . $product->category->name . '</span>') : 'category not known'!!}</td>
CodePudding user response:
Are You looking for this shorthand?
<span >{{$product->category->name ?? 'category not known'}}</span><br>
This is called the "null coalescing operator"
It returns its first operand if it exists and is not NULL; otherwise it returns its second operand.