Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel app service provider register

// 1: in Providers/*ServiceProvider  if SomeClass does not have args in __construct function.
public function register()
{
  $this->app->bind(
    PathToSomeClassInterface::class,
    PathToSomeClass::class
  );
}
      
// 2: in Providers/*ServiceProvider if someClass has args in __construct function.
public function register()
{
  $this->app->bind(
    PathToSomeClassInterface::class,
    fn () => new PathToSomeClass(args)
  );
}
 
PREVIOUS NEXT
Tagged: #laravel #app #service #provider #register
ADD COMMENT
Topic
Name
2+7 =