Hi Bobby,
this solution does not work.
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
\Illuminate\Support\Str::macro('removeSpaces', function (string $value) {
return preg_replace('/[\s]+/u', '', $value);
});
}
}
If I try Str::removeSpaces("aho a") that works great, but fluent access does not:
Str::of("aho a")->removeSpaces()
Exists with
BadMethodCallException with message 'Method Illuminate/Support/Stringable::removeSpaces does not exist.'
I also prefer not to register this with Providers. This causes the code is executed each time and performance goes down. A better solution would be on demand (like use class).
Thank you!