Category: PHP

Rendering stuffs conditionally is the most common job for programmers of any language and when it comes to PHP developers, the sight of html all mixed up with php logic is 😪. you know) you pass in an object whose keys are class names, and values are boolean expressions to determine if those class names are applied or not the concept is same, you pass an associative array where the key is the string to render & the value stands as boolean expression to resolve whether the string to be rendered / printed (for current example html class attribute value) the readability is much better & looks neat 😍 we can create a string macro on Illuminate\Support\Str helperclass to make things tidy, here is how :- in app/Providers/AppServiceProvider.php or if you have any other custom Provider class, go to the bootmethod now you can use in your blade view as Str::classNames([ … This quick tip is heavi ly inspired by Alpine JS and a recent great pull request made to Laravel core framework where I found this technique. very soon you’ll be able to write something similar for blade-x components in Laravel as the pull request got merged. Written by
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners