Support the ongoing development of Laravel.io →
posted 9 years ago
Forms
Last updated 2 years ago.
0

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.

0

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()

Last updated 9 years ago.
0

Did you pull in the 'Illuminate\Html' package? The HtmlBuilder class uses the 'Illuminate\Support\Traits\Macroable' trait.

Last updated 9 years ago.
0

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.

0

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()  {}

}
0

Sign in to participate in this thread!

Eventy

Your banner here too?

EvilKiwi evilkiwi Joined 30 Sep 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.