59 lines
1.1 KiB
PHP
59 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Visitor;
|
|
|
|
use App\Helpers\PageRenderer;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Content;
|
|
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(Content $page)
|
|
{
|
|
// test if loaded page is visible or not
|
|
if ($page->status == Content::STATUS_PROTECTED && !Auth::user()) {
|
|
throw new \Exception('Cannot access protected resources');
|
|
}
|
|
|
|
// add one new "view" for page
|
|
$page->view();
|
|
|
|
return PageRenderer::render($page);
|
|
}
|
|
}
|