Search⌘ K
AI Features

Extending Strings with Macros and Mixins

Explore how to extend Laravel's string capabilities by adding custom methods through macros and mixins. Learn to inject new functionality into the Str helper and fluent string classes, enabling powerful and organized string manipulation within your PHP applications.

Laravel provides two primary ways to add additional capabilities to the Str helper class and fluent strings: mixins and macros. Macros allow us to add new helper methods, and mixins enable us to inject the methods of a different class into either the Str helper class or fluent strings. We will be making great use of them throughout the rest of this course as we work to expand our knowledge of string management. Developers proficient in languages like C# can equate these features to the extension methods those languages provide.

For example, the code below defines a C# ...