The #[Bind]
attribute in Laravel allows you to specify which implementation of an interface should be automatically injected, eliminating the need for additional service registration in your service providers.
namespace App\Contracts;
use App\Services\StripePaymentProcessor;
use App\Services\MockPaymentProcessor;
use Illuminate\Container\Attributes\Bind;
#[Bind(StripePaymentProcessor::class)]
#[Bind(MockPaymentProcessor::class, environments: ['local'])]
interface PaymentProcessor
{
public function processPayment(float $amount): bool;
}