use Illuminate\Support\Arr; $array = ['p-4', 'font-bold' => $isActive, 'bg-red' => $hasError]; $isActive = false;$hasError = true; $classes = Arr::toCssClasses($array); /* * 'p-4 bg-red' */
Tip given by @dietsedev
Only until Jan 16th: coupon RESOLUTION25 for 40% off Yearly/Lifetime membership!
Read more hereuse Illuminate\Support\Arr; $array = ['p-4', 'font-bold' => $isActive, 'bg-red' => $hasError]; $isActive = false;$hasError = true; $classes = Arr::toCssClasses($array); /* * 'p-4 bg-red' */
Tip given by @dietsedev