mirror of
https://github.com/archtechx/laravel-pages.git
synced 2025-12-12 09:54:03 +00:00
add source code
This commit is contained in:
commit
e534ddd14c
23 changed files with 798 additions and 0 deletions
33
src/PageController.php
Normal file
33
src/PageController.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?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)) {
|
||||
seo()
|
||||
->title($model->title)
|
||||
->description(Str::limit($model->content, 100));
|
||||
|
||||
return view(config('pages.views.markdown'), ['page' => $model]);
|
||||
}
|
||||
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue