New in Laravel 8.51: @class
Blade directive to add true/false conditions on whether some CSS class should be added. Read more in docs
Before:
1<div class="@if ($active) underline @endif">`
Now:
1<div @class(['underline' => $active])>
1@php 2 $isActive = false; 3 $hasError = true; 4@endphp 5 6<span @class([ 7 'p-4', 8 'font-bold' => $isActive, 9 'text-gray-500' => ! $isActive,10 'bg-red' => $hasError,11])></span>12 13<span class="p-4 text-gray-500 bg-red"></span>
Tip given by @Teacoders