2020-03-29 01:03:52 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Frontend;
|
|
|
|
|
|
|
|
use App\Contracts\Controller;
|
|
|
|
use App\Exceptions\PageNotFound;
|
2020-07-11 01:11:38 +08:00
|
|
|
use App\Exceptions\Unauthorized;
|
2020-03-29 01:03:52 +08:00
|
|
|
use App\Repositories\PageRepository;
|
|
|
|
use Exception;
|
2020-07-11 01:11:38 +08:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2020-03-29 01:03:52 +08:00
|
|
|
|
|
|
|
class PageController extends Controller
|
|
|
|
{
|
|
|
|
private $pageRepo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \App\Repositories\PageRepository $pageRepo
|
|
|
|
*/
|
|
|
|
public function __construct(PageRepository $pageRepo)
|
|
|
|
{
|
|
|
|
$this->pageRepo = $pageRepo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the page
|
|
|
|
*
|
|
|
|
* @param $slug
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function show($slug)
|
|
|
|
{
|
2020-07-11 01:11:38 +08:00
|
|
|
/** @var \App\Models\Page $page */
|
2020-03-29 01:03:52 +08:00
|
|
|
$page = $this->pageRepo->findWhere(['slug' => $slug])->first();
|
|
|
|
if (!$page) {
|
|
|
|
throw new PageNotFound(new Exception('Page not found'));
|
|
|
|
}
|
|
|
|
|
2020-07-11 01:11:38 +08:00
|
|
|
if (!$page->public && !Auth::check()) {
|
|
|
|
throw new Unauthorized(new Exception('You must be logged in to view this page'));
|
|
|
|
}
|
|
|
|
|
2020-03-29 01:03:52 +08:00
|
|
|
return view('pages.index', ['page' => $page]);
|
|
|
|
}
|
|
|
|
}
|