I did this a few days ago. I created a MacroServiceProvier.php, registered it at config/app.php and included the macros within its boot method.
You can copy Providers/AppServiceProvider.php to start from.
micaweb said:
I did this a few days ago. I created a MacroServiceProvier.php, registered it at config/app.php and included the macros within its boot method.
You can copy Providers/AppServiceProvider.php to start from.
Mind giving an example? I've tried this and get the following error:
FatalErrorException in Facade.php line 213: Call to undefined method Illuminate\Html\FormFacade::macro()
Did you pull in the 'Illuminate\Html' package? The HtmlBuilder class uses the 'Illuminate\Support\Traits\Macroable' trait.
juukie14 said:
Did you pull in the 'Illuminate\Html' package? The HtmlBuilder class uses the 'Illuminate\Support\Traits\Macroable' trait.
Yes, I've added it to my composer file and pulled it in.
This is what works for me:
<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use File;
class MacroServiceProvider extends ServiceProvider {
/**
* Bootstrap any necessary services.
*
* @return void
*/
public function boot()
{
// Load Html and Form macros
foreach(File::glob(app_path() .'/Library/macros/*.php') as $macro) require $macro;
}
/**
* Register the service provider.
*
* @return void
*/
public function register() {}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community