man-u-l
2 weeks ago
124
4
Laravel

How to add a done() macro to the Srt::() class

Posted 2 weeks ago by man-u-l

I recently need it to cast a Str::() result to string, I got some help and I was told to ad ->__toString() to get the desired result, that worked great, but in the video: https://laracasts.com/series/whats-new-in-laravel-7/episodes/2 Someone mentioned:

"First thing I did was to add a done() macro to the class to return the value e.g.

Str::of(‘text’)->append(‘content’)->done();

IMO it’s cleaner than using (string) or ->__toString()"

->done() looks much better and cleaner than ->__toString()

How can this be done.

Thanks in advanced!

Please sign in or create an account to participate in this conversation.