Laravel Auto-Binder is an awesome package that adds the possibility to bind interfaces to implementations in the Service Container by scanning the specified project folders. This helps avoid manually registering container bindings when the project needs to bind a lot of interfaces to its implementations.

Define in your ServiceProvider: AutoBinder::from(folder: 'Services') ->as('singleton') ->bind(); Assuming you have your services in the App\Services and its interfaces in the App\Services\Interfaces, the package will register binding for each pair of class and interface: $this->app->singleton(AuthServiceInterface::class, AuthService::class); $this->app->singleton(UserServiceInterface::class, UserService::class); $this->app->singleton(CompanyServiceInterface::class, CompanyService::class); Customization

If you need to change the naming convention of your interfaces, you can specify the namespace and name you prefer: AutoBinder::from(folder: 'Services') ->interfaceNaming('Contract') ->bind(); This configuration scans the app/Services folder with App\Services namespace, App\Services\Contracts interface namespace and ClassNameContract interface naming convention. You might as well exclude subdirectories from the scan of the root directory: AutoBinder::from(folder: 'Services') ->exclude('Traits', 'Components') ->bind(); Scanning multiple folders at once
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners