Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

quickee's avatar

Interface binding question

I keep getting the error blew and im not sure why.. Any ideas?

App\Actions\Payment\MakeACardPayment::__construct(): Argument #1 ($service) must be of type App\Contracts\PaymentInterface, string given, called in /srv/decafapp.com/decaf-laravel/app/Providers/ActionServiceProvider.php

//inside AppServiceProvider

    App::bind(PaymentInterface::class,function(){
            return new StripePaymentService();
        });

//inside ActionServiceProvider

 $this->app->bind(MakeACardPayment::class, function($app){
            return new MakeACardPayment(PaymentInterface::class);
        });

//included in config/app.php

App\Providers\AppServiceProvider::class,
        App\Providers\ActionServiceProvider::class

//Make A CardPayment class

class MakeACardPayment 
{
    private $service;

    public function __construct(PaymentInterface $service)
    {
        $this->service = $service;
    }

    public function execute($data)
    {
   

        $this->service->ChargeCard($data);
    }

}

//stripe service

class StripePaymentService implements PaymentInterface
{

// no construct

0 likes
5 replies
Tippin's avatar

Why are you binding your MakeACardPayment action class? You've already defined how to resolve the interface the action class depends upon, but your action itself, unless implementing an interface, doesn't need to be bound. Your issue is:

MakeACardPayment(PaymentInterface::class);

Not only does it seem the action doesn't need to be bound, but you are trying to supply it with a FQN class, which is a string, not an instantiated object.

quickee's avatar

@Tippin Because im passing it into this controller as a dependency

class PaymentController extends Controller
{
    public function store(Request $request,CartInterfaceNoSession $service, MakeACardPayment $cardAction)
    { 
$cardAction->execute();

quickee's avatar

@Tippin i never really was able to get it to work without adding the bind, it always said the class needs to be an instance. Either way, when i remove that binding like you suggest the post failed to a 500 error - and its not logging the error for some reason, so im not sure what the problem is. App debug is true and logs every other 500 error..

Adding it back goes right back to the original error. So it seems to need the binding

quickee's avatar

gonna bump this. Still haven't found a solution to this.

Please or to participate in this conversation.