I am not sure if this is a Laravel question or a basic PHP question.
We have one site that is built up of lots of microsites. The functionality is shared across all microsites, it is really just the look and feel of each microsite that is different.
In our structure, we have one controller called HierarchyController, which each microsite uses. As you can probably gather, this controller is responsible for getting the page hierarchy of whatever microsite you happen to be viewing at the time. The controller resembles the following
Class HierarchyController extends BaseController
{
public function index(Request $request)
{
... do some stuff ...
$page_data = [
'something' => 'something_else',
];
return view('common.pages.hierarchy', $page_data);
}
}
Nothing difficult so far. But now I need the HierarchyController for just a handful of microsites to contain their own properties as well as the properties from the HierarchyController. I figured I could just create a microsite specific HierarchyController which extends the main controller above. Something like:
Class MicrositeHierarchyController extends HierarchyController
{
public function index(Request $request)
{
parent::index($request);
$page_data = array_merge(--parent_page_data--, [
'something1' => 'something_else_1',
]);
return view('microsite.pages.hierarchy', $page_data);
}
}
Because the parent HierarchyController returns a view and not an array, I am unsure how I can get to the $page_data from the calling class. Is this even possible?
Thanks
You could capture the view returned by the parent controller and perform a merge with it's data.
class MicrositeHierarchyController extends HierarchyController
{
public function index(Request $request)
{
$view = parent::index($request);
$page_data = array_merge($view->getData(), [
'something1' => 'something_else_1',
]);
return view('microsite.pages.hierarchy', $page_data);
}
}