Support the ongoing development of Laravel.io →
Database IOC

Firstly, sorry about the long title, but I was trying to be rather specific... Now to the actual question:

I have an interface which uses a command to run a registration process. Now, in my command handler, I use repository interfaces to connect to my models. I then resolve my two interfaces (which are bound to the app through a service provider) in the class constructor. My first repository is resolved correctly, but for the second one I receive the following error:

Argument 2 passed to App\Handlers\Commands\RegisterNewBookingCommandHandler::__construct() must implement interface storage\repositories\EventsRepository, instance of storage\repositories\EloquentEventsRepository given

From what I can deduce, I'm resolving the implementation class rather than my repository interface from the IoC. Below you'll see the relevant code of relevant files, hoping this mystery can somehow be resolved! I'm guessing I just missed something silly since I'm completely new to Laravel.

App/Http/Controllers/RegistrationController.php [the controller]

<?php namespace App\Http\Controllers;

use App\Commands\RegisterNewBookingCommand;
use App\Http\Requests\RegisterNewBookingRequest;

class RegistrationController extends Controller {


	public function __construct()
	{
		$this->middleware('guest');
	}

	public function index() {
		return view('form');
	}

	public function registerNewBooking(RegisterNewBookingRequest $request) {
		$this->dispatchFrom(RegisterNewBookingCommand::class, $request);
	}
}

app/Handlers/Commands/RegisterNewBookingCommandHandler.php

<?php namespace App\Handlers\Commands;

use App\Commands\RegisterNewBookingCommand;

use Illuminate\Queue\InteractsWithQueue;

use storage\repositories\BookingsRepository as Bookings;
use storage\repositories\EventsRepository as Events;

class RegisterNewBookingCommandHandler {

	/**
	 * Create the command handler.
	 *
	 * @return void
	 */
	public $booking;
	public $event;

	function __construct(Bookings $booking, Events $event)
	{
		$this->booking = $booking;
		$this->event = $event;
	}

        //a few helper functions that I excluded here

        /**
	 * Handle the command.
	 *
	 * @param  RegisterNewBookingCommand  $command
	 * @return void
	 */
	public function handle(RegisterNewBookingCommand $command)
	{
            //I run a few functions here
        }

storage/StorageServiceProvider.php

<?php namespace storage;

use Illuminate\Support\ServiceProvider;

class StorageServiceProvider extends ServiceProvider
{

    public function register()
    {
        $this->app->bind(
            'storage\repositories\EventsRepository',
            'storage\repositories\EloquentEventsRepository'
        );
        $this->app->bind(
            'storage\repositories\BookingsRepository',
            'storage\repositories\EloquentBookingsRepository'
        );
    }

}

So if there is any kind soul out there able to help me, I will be forever in your debt!

Last updated 3 years ago.
0

Do you have "... implements EventsRepository" operator in the EloquentEventsRepository class?

Last updated 10 years ago.
0

TorchSK said:

Do you have "... implements EventsRepository" operator in the EloquentEventsRepository class?

sighs how did I possibly miss that?!

Thanks a bunch

0

No problem! happens to me all the time :))

0

Sign in to participate in this thread!

PHPverse

Your banner here too?

phroggyy phroggyy Joined 30 Jan 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.