在laravel 5中放置HTML宏的位置?

hah*_*ute 9 macros laravel-5

在laravel 4中,我曾经有过在多个视图中使用的HTML宏,例如:

HTML::macro('minipics', function($pic)
{
    //
}
Run Code Online (Sandbox Code Playgroud)

为此我在macros.php文件/app夹中有一个文件.我无法找到将宏放在laravel 5的哪个位置.我应该使用'macroable'功能吗?

编辑:

我最终使用@include(),给它所需的值.

@include('shared.minipics', $mpics = $ppics)
@include('shared.minipics', $mpics = $randpics)
Run Code Online (Sandbox Code Playgroud)

小智 23

我已将我的宏移动到"resources/macros/..."目录中,因为我认为它们属于所有其他与视图相关的代码.要加载它们我使用的服务提供程序看起来像这样:

<?php namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class MacroServiceProvider extends ServiceProvider {

    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        require base_path() . '/resources/macros/macro1.php';
        require base_path() . '/resources/macros/macro2.php';
        // etc...
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

}
Run Code Online (Sandbox Code Playgroud)

  • 要添加到此,如果在引导方法中使用以下内容:`foreach(glob(base_path('resources/macros/*.baster.php'))as $ filename){require_once($ filename); 你可以自动加载所有<file> .macro.php文件,无需更新提供程序 (4认同)