What is the correct way of doing this?
@Leff7 To use the service container to resolve your dependencies. You shouldn’t be instantiating a controller from anywhere in your code though.
Instead, wrap your import logic into a class of its own, and then pull that class into where you need it:
class Importer
{
public function __construct(Importable $data)
{
$this->data = $data;
}
}
class ImportController extends Controller
{
public function __construct(Importer $importer)
{
$this->importer = $importer;
}
}
class ImportCommand extends Command
{
public function __construct(Importer $importer)
{
$this->importer = $importer;
}
public function handle()
{
// Use $this->importer
}
}