HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/anvil.komma.pro/app/KommaApp/Pages/CompanyPagesComposer.php
<?php

namespace App\KommaApp\Pages;

use App\KommaApp\Pages\Models\Page;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\View\View;

class CompanyPagesComposer
{
    public static $companies;

    /**
     * Bind data to the view.
     *
     * @param View $view
     * @return void
     */
    public function compose(View $view)
    {
        if (! static::$companies) {
            $site = \App::getSite();

            // Get the group page from the Anvil site
            $overviewPage = Page::where('code_name', 'group')
                ->where('site_id', $site->id)
                ->first();

            // Get the children because those will be the links
            $companies = $overviewPage->findChildren();

            // Also add the anvil overview page as link to anvil
            $companies = new Collection(array_prepend($companies, $overviewPage));

            // Only active companies
            $companies = $companies->where('active', 1);

            //Load the relation to prevent queries
            $companies->load('translation', 'translation.route');

            static::$companies = $companies;
        }

        $view->with('companies', static::$companies);
    }
}