Laravel - Blade Templates - Conditionally Merge Classes

Sometimes you may wish to merge classes if a given condition is true. You can accomplish this via the class method, which accepts an array of classes where the array key contains the class or classes you wish to add, while the value is a boolean expression. If the array element has a numeric key, it will always be included in the rendered class list:

    
    
class(['p-4', 'bg-red' => $hasError]) }}> {{ $message }}

If you need to merge other attributes onto your component, you can chain the merge method onto the class method:

    
    
	
If you need to conditionally compile classes on other HTML elements that shouldn't receive merged attributes, you can use the @class directive.