Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put HTML macros in laravel 5?

In laravel 4 I used to have HTML macros which were used in multiple views, like:

HTML::macro('minipics', function($pic)
{
    //
}

For that I had a macros.php file in the /app folder. I could not find out where to put the macros in laravel 5. Should I use the 'macroable' feature for that?

edit:

I ended up using @include(), giving it the needed values.

@include('shared.minipics', $mpics = $ppics)
@include('shared.minipics', $mpics = $randpics)
like image 735
haheute Avatar asked Feb 05 '15 13:02

haheute


1 Answers

I've moved my macros into a "resources/macros/..." directory because I think they belong with all of the other view related code. To load them I'm using a service provider which looks something like this:

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

}
like image 164
David Collingwood Avatar answered Oct 10 '22 12:10

David Collingwood