I have a Service Provider in Laravel which looks like this:
class ImportServiceProvider extends ServiceProvider
{
protected $importable = [
\MyApp\Agencies\AgencyImporter::class
];
/**
* Register the application services.
*
* @return void
*/
public function register()
{
$this->app->resolving(Importer::class, function (Importer $importer, $app) {
foreach($this->importable as $implementation) {
$importer->attach($app->make($implementation));
}
});
}
}
The idea being, a number of object can be added as Observers to the Importer
class when it is instantiated.
However, when I reach this line in the code, I get a Segmentation Fault
error:
$app->make($implementation)
However, if I run the code with a hardcoded class before the closure, it works fine:
$app->make(\MyApp\Agencies\AgencyImporter::class);
$this->app->resolving(Importer::class, function (Importer $importer, $app) {
foreach($this->importable as $implementation) {
//$importer->attach($app->make($implementation));
}
});
So it seems to be issue with the closure. Why this happens?