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)
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()
{
//
}
}
You can do it the same way as in Laravel 4.
Place your macros.php
file in the /app
folder.
Then in your composer.json
you do this
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
},
"files": [
"app/macros.php" <-- Put this here
]
},