phase two updates

This commit is contained in:
Mark Gregory
2026-07-24 09:45:41 +01:00
parent c2a19a16e6
commit 9204625c2f
114 changed files with 1480 additions and 1 deletions
+3
View File
@@ -0,0 +1,3 @@
<?php
return ['name' => 'Pages'];
@@ -0,0 +1,18 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void { Schema::create('pages', function (Blueprint $table): void { $table->id();
$table->string('title');
$table->string('slug');
$table->text('summary')->nullable();
$table->longText('content')->nullable();
$table->string('status')->default('draft');
$table->timestamp('published_at')->nullable();
$table->boolean('is_home')->default(false);
$table->timestamps(); $table->softDeletes(); }); }
public function down(): void { Schema::dropIfExists('pages'); }
};
@@ -0,0 +1,31 @@
<?php
namespace Modules\Pages\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Modules\Pages\Models\Page;
final class PageController extends Controller
{
public function index(): View { return view('pages::admin.index', ['records' => Page::query()->latest()->paginate(20)]); }
public function create(): View { return view('pages::admin.form'); }
public function store(Request $request): RedirectResponse { $data = $request->validate(['title' => ['required', 'string', 'max:255'],
'slug' => ['required', 'string', 'max:255'],
'summary' => ['nullable', 'string'],
'content' => ['nullable', 'string'],
'status' => ['required', 'string', 'max:255'],
'published_at' => ['nullable', 'date'],
'is_home' => ['sometimes', 'boolean']]); $data['is_home'] = $request->boolean('is_home'); Page::create($data); return redirect()->route('pages.index')->with('status', 'Page created.'); }
public function edit(Page $page): View { return view('pages::admin.form', ['record' => $page]); }
public function update(Request $request, Page $page): RedirectResponse { $data = $request->validate(['title' => ['required', 'string', 'max:255'],
'slug' => ['required', 'string', 'max:255'],
'summary' => ['nullable', 'string'],
'content' => ['nullable', 'string'],
'status' => ['required', 'string', 'max:255'],
'published_at' => ['nullable', 'date'],
'is_home' => ['sometimes', 'boolean']]); $data['is_home'] = $request->boolean('is_home'); $page->update($data); return redirect()->route('pages.index')->with('status', 'Page updated.'); }
public function destroy(Page $page): RedirectResponse { $page->delete(); return back()->with('status', 'Page deleted.'); }
}
@@ -0,0 +1,6 @@
<?php
namespace Modules\Pages\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\View\View;
use Modules\Pages\Models\Page;
final class PublicPageController extends Controller { public function show(string $slug): View { $page=Page::query()->where('slug',$slug)->where('status','published')->where(fn($q)=>$q->whereNull('published_at')->orWhere('published_at','<=',now()))->firstOrFail(); return view('pages::public.show',compact('page')); } }
+20
View File
@@ -0,0 +1,20 @@
<?php
namespace Modules\Pages\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
final class Page extends Model
{
use HasFactory, SoftDeletes;
protected $table = 'pages';
protected $fillable = ['title', 'slug', 'summary', 'content', 'status', 'published_at', 'is_home'];
protected function casts(): array { return [
'published_at' => 'datetime',
'is_home' => 'boolean'
]; }
}
@@ -0,0 +1,20 @@
<?php
namespace Modules\Pages\Providers;
use Illuminate\Support\ServiceProvider;
final class PagesServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->register(RouteServiceProvider::class);
$this->mergeConfigFrom(module_path('Pages', 'Config/config.php'), 'pages');
}
public function boot(): void
{
$this->loadMigrationsFrom(module_path('Pages', 'Database/Migrations'));
$this->loadViewsFrom(module_path('Pages', 'Resources/views'), 'pages');
}
}
@@ -0,0 +1,15 @@
<?php
namespace Modules\Pages\Providers;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
final class RouteServiceProvider extends ServiceProvider
{
public function boot(): void
{
parent::boot();
$this->routes(fn () => Route::middleware('web')->group(module_path('Pages', 'Routes/web.php')));
}
}
@@ -0,0 +1,11 @@
<x-layouts.app :title="isset($record) ? __('Edit Page') : __('Create Page')">
<div class="mx-auto max-w-4xl space-y-6"><div><h1 class="text-2xl font-semibold">{{ isset($record) ? 'Edit' : 'Create' }} Page</h1></div><form method="POST" action="{{ isset($record) ? route('administration.pages.update', $record) : route('administration.pages.store') }}" class="space-y-5 rounded-xl border border-zinc-200 bg-white p-6 dark:border-zinc-700 dark:bg-zinc-900">@csrf @isset($record) @method('PUT') @endisset
<div><label class="mb-1 block text-sm font-medium">Title</label><input type="text" name="title" value="{{ old('title', $record->title ?? '') }}" class="w-full rounded-lg border-zinc-300 dark:border-zinc-700 dark:bg-zinc-900">@error('title')<p class="text-sm text-red-600">{{ $message }}</p>@enderror</div>
<div><label class="mb-1 block text-sm font-medium">Slug</label><input type="text" name="slug" value="{{ old('slug', $record->slug ?? '') }}" class="w-full rounded-lg border-zinc-300 dark:border-zinc-700 dark:bg-zinc-900">@error('slug')<p class="text-sm text-red-600">{{ $message }}</p>@enderror</div>
<div><label class="mb-1 block text-sm font-medium">Summary</label><textarea name="summary" rows="4" class="w-full rounded-lg border-zinc-300 dark:border-zinc-700 dark:bg-zinc-900">{{ old('summary', $record->summary ?? '') }}</textarea>@error('summary')<p class="text-sm text-red-600">{{ $message }}</p>@enderror</div>
<div><label class="mb-1 block text-sm font-medium">Content</label><textarea name="content" rows="8" class="w-full rounded-lg border-zinc-300 dark:border-zinc-700 dark:bg-zinc-900">{{ old('content', $record->content ?? '') }}</textarea>@error('content')<p class="text-sm text-red-600">{{ $message }}</p>@enderror</div>
<div><label class="mb-1 block text-sm font-medium">Status</label><input type="text" name="status" value="{{ old('status', $record->status ?? '') }}" class="w-full rounded-lg border-zinc-300 dark:border-zinc-700 dark:bg-zinc-900">@error('status')<p class="text-sm text-red-600">{{ $message }}</p>@enderror</div>
<div><label class="mb-1 block text-sm font-medium">Published At</label><input type="datetime-local" name="published_at" value="{{ old('published_at', $record->published_at ?? '') }}" class="w-full rounded-lg border-zinc-300 dark:border-zinc-700 dark:bg-zinc-900">@error('published_at')<p class="text-sm text-red-600">{{ $message }}</p>@enderror</div>
<label class="flex items-center gap-2"><input type="checkbox" name="is_home" value="1" @checked(old('is_home', $record->is_home ?? false))><span>Is Home</span></label>
<div class="flex gap-3"><button class="rounded-lg bg-zinc-900 px-4 py-2 text-white dark:bg-white dark:text-zinc-900">Save</button><a href="{{ route('administration.pages.index') }}" class="rounded-lg border px-4 py-2">Cancel</a></div></form></div>
</x-layouts.app>
@@ -0,0 +1,5 @@
<x-layouts.app :title="__('Pages')">
<div class="space-y-6"><div class="flex items-center justify-between"><div><h1 class="text-2xl font-semibold">Pages</h1><p class="text-sm text-zinc-500">Manage pages content.</p></div><a href="{{ route('administration.pages.create') }}" class="rounded-lg bg-zinc-900 px-4 py-2 text-sm text-white dark:bg-white dark:text-zinc-900">Add new</a></div>
@if(session('status'))<div class="rounded-lg bg-emerald-50 p-3 text-emerald-800">{{ session('status') }}</div>@endif
<div class="overflow-hidden rounded-xl border border-zinc-200 bg-white dark:border-zinc-700 dark:bg-zinc-900"><table class="w-full text-sm"><thead class="bg-zinc-50 dark:bg-zinc-800"><tr><th class="px-4 py-3 text-left">Title</th><th class="px-4 py-3 text-left">Slug</th><th class="px-4 py-3 text-left">Summary</th><th class="px-4 py-3 text-right">Actions</th></tr></thead><tbody class="divide-y divide-zinc-200 dark:divide-zinc-800">@forelse($records as $record)<tr><td class="px-4 py-3">{{ is_array($record->title) ? json_encode($record->title) : Str::limit((string) $record->title, 70) }}</td><td class="px-4 py-3">{{ is_array($record->slug) ? json_encode($record->slug) : Str::limit((string) $record->slug, 70) }}</td><td class="px-4 py-3">{{ is_array($record->summary) ? json_encode($record->summary) : Str::limit((string) $record->summary, 70) }}</td><td class="px-4 py-3 text-right"><a class="mr-3 underline" href="{{ route('administration.pages.edit', $record) }}">Edit</a><form class="inline" method="POST" action="{{ route('administration.pages.destroy', $record) }}">@csrf @method('DELETE')<button class="text-red-600" onclick="return confirm('Delete this record?')">Delete</button></form></td></tr>@empty<tr><td colspan="4" class="px-4 py-10 text-center text-zinc-500">No records yet.</td></tr>@endforelse</tbody></table></div>{{ $records->links() }}</div>
</x-layouts.app>
@@ -0,0 +1 @@
<x-layouts.app :title="$page->title"><article class="prose mx-auto max-w-4xl py-10 dark:prose-invert"><h1>{{ $page->title }}</h1>@if($page->summary)<p class="lead">{{ $page->summary }}</p>@endif{!! $page->content !!}</article></x-layouts.app>
+10
View File
@@ -0,0 +1,10 @@
<?php
use Illuminate\Support\Facades\Route;
use Modules\Pages\Http\Controllers\PageController;
Route::middleware(['auth', 'verified'])->prefix('administration/pages')->name('administration.pages.')->group(function (): void {
Route::resource('/', PageController::class)->parameters(['' => 'page'])->except('show');
});
Route::get('/pages/{slug}', [Modules\Pages\Http\Controllers\PublicPageController::class, 'show'])->name('pages.public.show');
+5
View File
@@ -0,0 +1,5 @@
<?php
namespace Modules\Pages\Support;
final class ModuleInfo { public static function name(): string { return 'Pages'; } public static function nameLower(): string { return 'pages'; } }
@@ -0,0 +1,5 @@
<?php
use Illuminate\Support\Facades\Route;
it('registers the Pages administration route', function (): void { expect(Route::has('administration.pages.index'))->toBeTrue(); });
+20
View File
@@ -0,0 +1,20 @@
{
"name": "Pages",
"alias": "pages",
"version": "1.0.0",
"description": "Pages CMS module.",
"keywords": [
"cms",
"pages"
],
"priority": 21,
"providers": [
"Modules\\Pages\\Providers\\PagesServiceProvider"
],
"aliases": {},
"files": [],
"requires": [
"Core",
"Administration"
]
}