FEATURE #1427: add basic homepage support

This commit is contained in:
Michal Kváček
2016-02-15 17:09:50 +01:00
parent 36fc280f55
commit 6d0e6e26f6
3 changed files with 72 additions and 0 deletions
@@ -0,0 +1,43 @@
<?php
namespace App\Http\Controllers\Visitor;
use App\Http\Controllers\Controller;
use App\Http\Requests;
use App\Models\Content;
use Illuminate\Support\Facades\Auth;
class ContentPage extends Controller
{
public function getPage($url)
{
$page = Content::where('url', $url)
->where('status', '!=', Content::STATUS_DELETED)
->first();
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');
}
// get handler
$handler = new $page->module_handler;
// render page
return $handler->render($page, '');
// return call_user_func([$handler, 'render'], $page);
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace App\Http\Controllers\Visitor;
use App\Http\Requests;
use App\Models\Content;
use Symfony\Component\Process\Exception\InvalidArgumentException;
class Homepage extends ContentPage
{
public function getIndex()
{
// try to find some homepage
$page = Content::where('is_homepage', 1)
->where('status', '!=', Content::STATUS_DELETED)
->first();
// test if we have any homepage
if (!$page) {
throw new InvalidArgumentException('Cannot load home page!');
}
// render page
return $this->renderPage($page);
}
}
+3
View File
@@ -6,6 +6,9 @@
Route::group(['middleware' => ['web']], function () {
Route::get('/', 'Visitor\Homepage@getIndex')
->name('page.index');
// display login form
Route::get('login', function () {
return view('admin.loginForm.form');