I've read the docs, all sorts of web pages, and every kind of answer/question I could find but still not finding a solution to my problem. I have a Manager object that needs to retrieve data from the database, then depending on the data, instantiate a new class dynamically:
$workflow = new $class;
$workflow->process($id);
An example would be calling a NfN class that extends my WorkFlow abstract class and requires dependency injection:
class NotesFromNature extends WorkFlow
{
public function __construct(ExpeditionInterface $expedition)
{
$this->expedition = $expedition;
}
public process($id)
{
// .......
}
}
Is it possible to bind this in my service provider so it does not throw a missing argument error when calling "new $class" ?
$app->bind('Biospex\Services\WorkFlow\NotesFromNature', function($app)
{
return new NotesFromNature( ?? ExpeditionInterface?? );
});
because I've tried various variations on the above and can't get anything to work.
Was able to figure it out. In the Manager class, I called:
$workflow= App::make($class);
I did not need to set a binding in the service provider.
Can you help me with that? I try to do that pretty much the same thing... but... I want to Inject in Laravel 5.2 a dinamyc FormRequest
my code is to update a resource in the database but i want to validate depending of the uri...
// so instead of use Request i think i could use somethign like function update({$this->getClass()} $request, $space, $form)...
public function update(Request $request, $space, $form)
{
// $form is a slug of one record in my database, based on this variable i want to determinate which request i have to load dinamyc...
}
Do you see what i try to do?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community