You'll need to do both. Dependency injection always involves two steps:
First, define the dependencies the class will use in its constructor
class MyClass
{
// Can do this with or without type hints
public function __construct($dependency1, $dependency2)
{
...
}
}
Then from outside of that class, instantiate those dependencies and push them into that class:
$dependency1 = new Dependency1;
$dependency2 = new Dependency2;
$myClass = new MyClass($dependency1, $dependency2);
So how do you do the second step using Laravel & App::bind(), App::make()? Like this (you actually have two ways)
// Here's one way: it's basically the same as the above -
// we use the 'new' keyword to instantiate the two dependencies of 'MyClass'
App::bind('MyClass', function() {
$dependency1 = new Dependency1;
$dependency2 = new Dependency2;
return new MyClass($dependency1, $dependency2)
});
// Here's another way: we use App::make() to create the two dependencies:
App::bind('MyClass', function() {
$dependency1 = App::make('Dependency1');
$dependency2 = App::make('Dependency2');
return new MyClass($dependency1, $dependency2)
});
So why use App::make() for creating the dependencies instead of the new keyword?
Because if Dependency1 & 2 had dependencies of their own, you wouldn't want to have to manually wire together that object graph every time. App::make() loads all of those sub-dependencies for you.
Consider this final example:
App::bind('MyClass', function() {
// Create Dependency1 the hard/manual way, every time you want to use it....
$dependency1 = new Dependency1(
new OtherDependency(
new AnotherDependency('some', 'config', 'data', 'here'),
new MoreDependencies,
),
new ThisIsTiringDepenency,
new MotherOfGodDoINeedToDoThisEveryTime('nope', 'just', 'use', 'App::make()')?
);
// Or use App::make() to do it for you to save yourself a lot of time
$dependency1 = App::make('Dependency1');
return new MyClass($dependency1)
});
Just as a side not that's worth mentioning, don't use App::make() from inside your classes, that's using it like a service locator which is an anti-pattern, and hides the true dependencies of the class. Always inject your dependencies through a constructor, and then bind them into the IoC from a service provider using a combination of App::bind() and App::make() and new as needed