File: D:/HostingSpaces/Anvil/anvil-industries.com/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
{
static $companies;
/**
* Bind data to the view.
*
* @param View $view
* @return void
*/
public function compose(View $view)
{
if(!static::$companies){
// Get the group page from the Anvil site
$overviewPage = Page::where('code_name', 'group')
->where('site_id', 1)
->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);
}
}