我已经使用了条件href
和a
块。Laravel View - 提高可读性
如何让代码更清晰以提高可读性?
<a type="button" class="btn btn-sm text-complete" href="/settings/statuses/{{$status->id}}/@if ($status->enabled == 0) enable @else disable @endif">
@if ($status->enabled == 0) Enable @else Disable @endif
</a>
也许在你的'$ status'对象上创建一个URL属性(通过一个访问器)。'''' –
@BenSwinburne我认为这意味着我必须去通过repo或model中的$ status循环并添加href链接 –
如果'$ status'引用雄辩模型,则可以使用访问器(https://laravel.com/docs/master/eloquent-mutators#accessors和增变器)即时生成财产。 –