Trying to use the IoC as a factory. Can I pass data to initialize/construct object with?
App::bind('Song', function(){
return new Song;
});
and mimic this (can $data never gets passed along, why?)
App::bind('Song', function($data=null){
return new Song($data);
});
while the Class is
class Song extends Eloquent {
protected $fillable = array(
'id',
'name',
'type'
);
}
The App::make('Song',array('id'=>1,'name'=>'foo'))
call skips inserting my arguments inside Illuminate\Container - the initialized class does not contain any defined attributes.
You can pass data to an anonymous function using 'use':
App::bind('Song', function() use ($data) {
return new Song($data);
});
Define the Song object binding. $dynamicData
can be any concrete object, array or primitive type.
App::bind('Song', function($app, $dynamicData){
return new Song($dynamicData);
});
Pass the dynamic data to the concrete object
$song = App::make('Song', ['name' => 'foo', 'type' => 'bar']);