Skip to content

Commit

Permalink
[8.x] Added $attributes->class() to Blade docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbaljet authored Feb 5, 2021
1 parent 57f12d3 commit 22202a1
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions blade.md
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,33 @@ The final, rendered HTML of the component will appear like the following:
</div>
```

<a name="conditionally-merge-classes"></a>
#### Conditionally Merge Classes

You may conditionally merge a set of classes with the `class` method by passing an array of classes.

<div {{ $attributes->class(['p-4', 'mb-4']) }}>
{{ $message }}
</div>

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`.

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

If you need to pass other attributes, you can chain the `merge` method.

<button {{ $attributes->class(['p-4'])->merge(['type' => 'button']) }}>
{{ $slot }}
</button>

For convenience, the `class` method accepts a string as well.

<div {{ $attributes->class('p-4') }}>
{{ $message }}
</div>

<a name="non-class-attribute-merging"></a>
#### Non-Class Attribute Merging

Expand Down

0 comments on commit 22202a1

Please sign in to comment.