I dont know if it's the "best practice" but I have many cases where i must inject 2 repositories in a controller. It's simple and easy for tests.
Using Multiple Repositories in Controller
I'm trying to determine the best way to include a reference to more than one repo in a single controller.
I've got a "SubjectsController" which very closely follows the standard repository pattern:
class SubjectsController extends BaseController
{
/**
* @var Cmapp\Interfaces\SubjectRepositoryInterface $repo
*/
public $repo;
/**
* __construct method
* Inject our Subject repository
*
* @param SubjectRepositoryInterface $repo
*/
public function __construct( SubjectRepositoryInterface $repo )
{
$this->repo = $repo;
}
I'm fine with all of this. My issue is in my "create" method, I need to pass a list() from another model to my view for a simple form drop down.
public function create()
{
# List of available studies for assignment
$studies = Study::lists('name', 'id');
return View::make('manager.subjects.create')->with(compact('studies'));
}
How do I access my Study repo (I do have one), so that I'm not dependent on the Eloquent Model in my controller? Do I inject it in my controller constructor alongside my Subjects repo? Do I make it available to my view using a View Composer? What's the "best practice" here?
Seems like overkill to DI this for a single method in my controller. I have tried this approach and it works fine, just not sure if this is the correct thing to do.
Please or to participate in this conversation.