Thursday, March 16, 2017

Edit parent variable

So I'm trying to edit the property category from the child class, but for some reasons I'm getting back an error. This I know why because there needs to be 2 arguments, but one is allready set in de parent class.

Code:

The Child

class RestaurantController extends CompanyController
{
    public function __construct(){
        parent::__construct(null, "restaurant");
        //$this->category = "restaurant";
    }
    public function getCompany($slug){
        $company = parent::index($slug);
        return view("restaurant.profile")->withInformation($company);
    }
} 

The Parent

class CompanyController extends Controller 
{
    protected $company;
    public $category;

    public function __construct(CompanyRepository $company, $category = '')
    {
        $this->category = $category;
        $this->company = $company;
    }

    public function index($slug)
    {
        $company = $this->company->getCompany($this->category, $slug);

        return compact('company');
    }
}

Now I need to know how to work a way around it.



via DevJoeri

Advertisement