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?
I ended up using @include()
, giving it the needed values.
@include('shared.minipics', $mpics = $ppics)
@include('shared.minipics', $mpics = $randpics)
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()
{
//
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With