<?php

namespace App\Composers;

use App\Interfaces\MenuInterface;
use App\Interfaces\UserInterface;
use Request;

// called inside of filters.php file
class AppComposer
{
    public $data;
    public $menu;
    public $user;
    public $banner;

    public function __construct(MenuInterface $menu)
    {
        $this->menu = $menu;
    }

    public function compose($view)
    {
        // init values
        $this->data['COMPOSE_MENU'] = $this->menu->getMenuStruct();
        // pass values
        $view->with('COMPOSE_MENU', $this->data['COMPOSE_MENU']);
        // get banners
        // this part is important if banner is inside header file or any other partial view
        // when is this commented that mean banners are loaded inside controller
        $segment = Request::segment(1);
        // get banner id by current page slug
        $menupage = $this->menu->bySlug($segment);
        if (is_object($menupage)) {
            $parents = $this->menu->getParents($menupage->id);
        }
    }
}
