Create multiple register functions like
public function registerUserRepo() {....}
public function registerComplaintRepo() {....}
and then call these functions in main register function
Tried this way:
<?php
namespace Storage;
use Illuminate\Support\ServiceProvider;
class StorageServiceProvider extends ServiceProvider {
public function register() {
registerUserRepo();
registerComplaintRepo();
registerComplaintRepo();
}
public function registerUserRepo() {
return $this->app->bind('Storage\User\UserRepository', 'Storage\User\EloquentUserRepository');
}
public function registerComplaintRepo() {
return $this->app->bind('Storage\Complaint\ComplaintRepository', 'Storage\Complaint\EloquentComplaintRepository');
}
public function registerComplaintRepo() {
return $this->app->bind('Storage\Category\CategoryRepository', 'Storage\Category\EloquentCategoryRepository');
}
}
thew me an error: Cannot redeclare Storage\StorageServiceProvider::registerComplaintRepo()
What i am doing wrong? (sorry for being noob)
You have the last function name wrong. Should be registerCategoryRepo not registerComplaintRepo (which is a redeclare of already declared function)
TorchSK said:
You have the last function name wrong. Should be registerCategoryRepo not registerComplaintRepo (which is a redeclare of already declared function)
lol, fixed that. Now i am getting this error: Call to undefined function Storage\registerUserRepo()
Call the functions in $this context in register function
public function register()
{
$this->registerUserRepo();
$this->registerComplaintRepo();
$this->registerCategoryRepo();
}
And I think the return in
return $this->app->bind(...)
is unnecessary
It works! Thank you. Was checking laravel docs about IoC container, but didn't found info about multiple bindings :(
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community