Accessing repository pattern through one more layer called service in Laravel -
i have created 1 repository layer in project accessible through controller method using interface. want add, service layer. means want controller method operations done through service. created 1 file inside service folder , tried access of repository functions through service.
there have crated 1
constructor repository access .. getting error
public function __construct(ifamilyrepository $familyrepository){ $this->$familyrepository = $familyrepository; // getting error on line } public function testrepository(){ $this->$familyrepository->getallgrandfather(); return "null"; }
i getting error :
errorexception in familyservice.php line 19: object of class app\repositories\eloquent\familyrepository not converted string in familyservice.php line 19 @ handleexceptions->handleerror('4096', 'object of class app\repositories\eloquent\familyrepository not converted string', 'd:\files\xampp\htdocs\laravel\dolovers-project-nayeb-moshai\app\services\familyservice.php', '19', array('familyrepository' => object(familyrepository))) in familyservice.php line 19 @ familyservice->__construct(object(familyrepository)) @ reflectionclass->newinstanceargs(array(object(familyrepository))) in container.php line 817 @ container->build('app\services\familyservice', array()) in container.php line 656
when access class variables, need $this->some_var
, not $this->$some_var
. in latter case, php thinks you're trying use string value of $some_var
, , can't - that's why it's complaining not being able convert string.
just changing should work right away, assuming other code correct.
public function __construct(ifamilyrepository $familyrepository){ $this->familyrepository = $familyrepository; } public function testrepository(){ $this->familyrepository->getallgrandfather(); return "null"; }
(also, beside - , know better me - should ifamilyrepository
, not familyrepository
?)
Comments
Post a Comment