laracasts / Presenter

Easy view presenters in your apps.
https://packagist.org/packages/laracasts/presenter
MIT License
864 stars 110 forks source link

Using a constructor in the Presenter Class #18

Open warksit opened 10 years ago

warksit commented 10 years ago

I have an Owner Model and an OwnerPresenter class. 'Standard' functionality os working fine. I am now trying to do something in a presenter part of which I will use in other presenters (but not all) so would like to utilise DI using a constructor in my Presenter Class. I get the following error:

Argument 1 passed to Owners\OwnerPresenter::__construct() must be an instance of Utilities\AddressBuilder, instance of Owners\Owner given, called in /home/vagrant/project1/vendor/laracasts/presenter/src/Laracasts/Presenter/PresentableTrait.php on line 29 and defined (View: /home/vagrant/project1/app/views/search.blade.php)

I have tried adding parent::_construct and parent::_construct($this->entity) but I am getting the same error.

I can see that there is a conflict with the constructors but struggling to work out how to solve it

marcusmoore commented 9 years ago

I'm in the same boat. Did you end up working something out?

cmorbitzer commented 6 years ago

For future reference, dependencies can be resolved using the resolve helper. https://laravel.com/docs/5.6/container#resolving