The Meaning Of Dependencies In Composer And Laravel Service Container

I am not familiar with composer and laravel.

according to the guide.

Composer is A Dependency Manager for PHP.

The Laravel service container is a powerful tool for managing class dependencies and performing dependency injection.

if composer manages a dependency, why service container is needed? they refer to different dependencies?

thanks in advance.



Composer deals with making copies of libraries available within the project at all. It ensures the libraries you have denoted as required are present in the vendor folder within your project. It doesn't know anything about you project or how these libraries are used, or if they are at all. Composer deals with which libraries your project depends on and makes sure they are available.

The Laravel service container deals with instantiating instances of classes at run time.

If you have a parameter to a constructor with a specific class type-hint, the service container is the piece which resolves that for you. e.g.

public function __construct(User $user)

The Laravel service container deals with run time dependencies and resolves classes in order to instantiates objects as needed.