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
41
src/Page.php
Normal file
41
src/Page.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ArchTech\Pages;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Orbit\Concerns\Orbital;
|
||||
|
||||
class Page extends Model
|
||||
{
|
||||
use Orbital;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public static function schema(Blueprint $table)
|
||||
{
|
||||
$table->string('slug');
|
||||
$table->string('title');
|
||||
$table->longText('content');
|
||||
}
|
||||
|
||||
public function getKeyName()
|
||||
{
|
||||
return 'slug';
|
||||
}
|
||||
|
||||
public function getIncrementing()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function routes(): void
|
||||
{
|
||||
Route::get('/{page}', config('pages.routes.handler'))
|
||||
->prefix(config('pages.routes.prefix'))
|
||||
->name(config('pages.routes.name'));
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
28
src/PagesServiceProvider.php
Normal file
28
src/PagesServiceProvider.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ArchTech\Pages;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class PagesServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
$this->loadViewsFrom(__DIR__ . '/../assets/views', 'pages');
|
||||
$this->mergeConfigFrom(__DIR__ . '/../assets/config.php', 'pages');
|
||||
|
||||
$this->publishes([
|
||||
__DIR__ . '/../assets/views' => resource_path('views/vendor/pages'),
|
||||
], 'archtech-pages-views');
|
||||
|
||||
$this->publishes([
|
||||
__DIR__ . '/../assets/config.php' => config_path('pages.php'),
|
||||
], 'archtech-pages-config');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue