Skip to content

Allow Macroables to override defined methods #42915

Closed Answered by joelmellon
joelmellon asked this question in Ideas
Discussion options

You must be logged in to vote

My current solution works quite well, although it doesn't use macros. It's a more traditional object oriented approach to extension.

I modified the Str alias in config/app.php to point to my own Str class that extends the Illuminate Str class. This is the best way I currently know how to "override" Str methods. This covers most usage, but not if developers use Illuminate\Support\Str; directly. From working on various projects, it’s quite common for developers to do that, so if I want to override a method or two I need to go through the whole project and replace all occurrences of use Illuminate\Support\Str;. It also doesn’t cover using the Str class alias before Laravel boots, eg. in a co…

Replies: 6 comments 20 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
6 replies
@joelmellon
Comment options

@henzeb
Comment options

@joelmellon
Comment options

@therecluse26
Comment options

@Sophist-UK
Comment options

Comment options

You must be logged in to vote
9 replies
@Sophist-UK
Comment options

@jose123v
Comment options

@therecluse26
Comment options

@joelmellon
Comment options

@Sophist-UK
Comment options

Answer selected by joelmellon
Comment options

You must be logged in to vote
3 replies
@joelmellon
Comment options

@Sophist-UK
Comment options

@joelmellon
Comment options

Comment options

You must be logged in to vote
1 reply
@parallels999
Comment options

Comment options

You must be logged in to vote
1 reply
@benbjurstrom
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
8 participants