Conditional Classes Blade Directives in Laravel
In this post we will give you information about Conditional Classes Blade Directives in Laravel. Hear we will give you detail about Conditional Classes Blade Directives in Laravel And how to use it also give you demo for it if it is necessary.
New in Laravel 10.51: @class
Blade directive to add true / false conditions on whether some CSS class should be added.
The @class
directive conditionally compiles a CSS class string. The directive 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:
@php
$hasError = true;
@endphp
<span @class([
'p-4',
'bg-red' => $hasError,
])></span>
Thank you for reading this blog.
Also see: How to Install React in Laravel 10
If you have any queries or doubts about this topic please feel free to contact us . We will try to reach you.
Hope this code and post will helped you for implement Conditional Classes Blade Directives in Laravel. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs