Files
core/app/Http/Controllers/Visitor/ContentPage.php
T

60 lines
1.2 KiB
PHP

<?php
namespace App\Http\Controllers\Visitor;
use App\Models\Content\Content as ContentModel;
use App\CMS\Contracts\Repositories\Content;
use App\CMS\Helpers\PageRenderer;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
class ContentPage extends Controller
{
/**
* @var Content
*/
protected $content;
/**
* @param Content $content
*/
function __construct(Content $content)
{
$this->content = $content;
}
public function getPage($url)
{
$page = $this->content->getByURL($url);
// no page available
if (!$page) {
abort(404);
}
return $this->renderPage($page);
}
/**
* Method used for rendering page for visitor
*
* @param Content $page
*
* @return mixed
* @throws \Exception
*/
protected function renderPage(ContentModel $page)
{
// test if loaded page is visible or not
if ($page->isProtected() && !Auth::user()) {
abort(404);
}
// add one new "view" for page
$page->view();
return PageRenderer::render($page);
}
}