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:
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.
<?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);
}
}
<?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
}
<?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!
Do you have "... implements EventsRepository" operator in the EloquentEventsRepository class?
TorchSK said:
Do you have "... implements EventsRepository" operator in the EloquentEventsRepository class?
sighs how did I possibly miss that?!
Thanks a bunch
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community