FEATURE #1427: add basic homepage support
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,9 @@
|
|||||||
|
|
||||||
Route::group(['middleware' => ['web']], function () {
|
Route::group(['middleware' => ['web']], function () {
|
||||||
|
|
||||||
|
Route::get('/', 'Visitor\Homepage@getIndex')
|
||||||
|
->name('page.index');
|
||||||
|
|
||||||
// display login form
|
// display login form
|
||||||
Route::get('login', function () {
|
Route::get('login', function () {
|
||||||
return view('admin.loginForm.form');
|
return view('admin.loginForm.form');
|
||||||
|
|||||||
Reference in New Issue
Block a user