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.
Edit1
The error I'm getting
Type error: Argument 1 passed to App\Http\Controllers\CompanyController::__construct() must be an instance of App\Repositories\CompanyRepository, null given, called in /var/www/atify.info/dev-system/app/Http/Controllers/RestaurantController.php on line 16
edit2
This Child
class RestaurantController extends CompanyController
{
public function getCompany($slug){
$company = parent::index($slug);
return view("restaurant.profile")->withInformation($company);
}
}
The Parent
use App\Repositories\CompanyRepository;
class CompanyController extends Controller
{
protected $company;
public function __construct(CompanyRepository $company)
{
$this->company = $company;
}
public function index($slug)
{
$company = $this->company->getCompany($slug);
return compact('company');
}
}
So then I needed a category (for extra check. Otherwise you could retrieve the company inside another child with wrong functions) because I have many childs and each child have special functions
via DevJoeri