File: D:/HostingSpaces/SBogers10/komma.pro/app/KommaApp/Pages/PageService.php
<?php
namespace App\KommaApp\Pages;
use App\KommaApp\Pages\Models\Page;
class PageService
{
/**
* Fetch translated page routes
*
* @return object | bool
*/
public function getAllTranslatedPageRoutes()
{
// Find all pages
if( ! $pages = Page::where('active',1)
->where('lft', '!=', 1)
->orderBy('lft','asc')
->with('translation')
->with('translation.route')
->get()
) return false;
$routes = [];
// Loop through pages
foreach($pages as $key => $page)
{
if(isset($page->translation) && isset($page->translation->route)){
$routes[$page->code_name] = (object)[
'name' => $page->translation->name,
'route' => $page->translation->route->alias,
'node' => $page
];
}
}
return (object)$routes;
}
/**
* Get page by specific code name
*
* @param $codeName
* @return Page
*/
public function getPageByCodeName($codeName): Page
{
if(!$page = Page::where('code_name','=', $codeName)
->with('translation')
->where('active', 1)
->first()) \App::abort(404);
return $page;
}
}