1
0
Fork 0
mirror of https://github.com/archtechx/laravel-pages.git synced 2025-12-12 01:44:03 +00:00
laravel-pages/src/PageController.php
2021-08-08 20:01:14 +02:00

37 lines
807 B
PHP

<?php
declare(strict_types=1);
namespace ArchTech\Pages;
use Illuminate\Support\Str;
class PageController
{
public function __invoke(string $page)
{
if (str_starts_with($page, '_')) {
abort(404);
}
$view = config('pages.views.path') . $page;
if (view()->exists($view)) {
return view($view);
}
if ($model = config('pages.model')::find($page)) {
if ($model->password) {
abort_unless(request()->query('password') === $model->password, 403);
}
seo()
->title($model->title)
->description(Str::limit($model->content, 100));
return view(config('pages.views.markdown'), ['page' => $model]);
}
abort(404);
}
}