Extending Strings with Macros and Mixins
Learn how to extend strings with the macros and mixins programming concepts.
We'll cover the following
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# extension method that would make the SplitLines
method available on strings:
Get hands-on with 1200+ tech skills courses.