From 22202a1d39b8bd22006a7b312dcef1752cad329f Mon Sep 17 00:00:00 2001 From: Pascal Baljet Date: Fri, 5 Feb 2021 10:50:06 +0100 Subject: [PATCH] [8.x] Added $attributes->class() to Blade docs Feature PR: https://github.com/laravel/framework/pull/36131 --- blade.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/blade.md b/blade.md index 07ef8ef19a0..46ae633b50f 100644 --- a/blade.md +++ b/blade.md @@ -906,6 +906,33 @@ The final, rendered HTML of the component will appear like the following: ``` + +#### Conditionally Merge Classes + +You may conditionally merge a set of classes with the `class` method by passing an array of classes. + +
class(['p-4', 'mb-4']) }}> + {{ $message }} +
+ +Sometimes you may wish to merge classes by specifying conditions. You can accomplish this by passing an array of classes where the array value evaluates to `true`. + +
class(['p-4', 'bg-red' => $hasError]) }}> + {{ $message }} +
+ +If you need to pass other attributes, you can chain the `merge` method. + + + +For convenience, the `class` method accepts a string as well. + +
class('p-4') }}> + {{ $message }} +
+ #### Non-Class Attribute Merging