Plugin-System; Neuigkeiten und Termine als mitgelieferte Plugins
- Plugins nach WordPress-Prinzip: plugin.json-Manifest mit Versions- und Abhängigkeitsprüfung, eigenes PSR-4-Autoloading, register()/boot(), activate()/deactivate()/uninstall(), Migrationen, Routen und Views je Plugin - plugins-core/ (mitgeliefert, aktiv bis zur Deaktivierung) und plugins/ (Kunden-Plugins, geschützt vor Updates, inaktiv bis zur Aktivierung) - Zustand in storage/app/plugins.json – Laden ohne Datenbankabfrage - Wiederherstellungsmodus: Ausnahmen und Fatal Errors beim Laden deaktivieren das Plugin, das Portal bleibt erreichbar - Hooks (Actions/Filter mit Prioritäten) und Registries für Navigation, Startseiten-Kacheln, Rechte und Admin-Seiten (Filament-Discovery) - Admin-Seite „Plugins“: aktivieren, deaktivieren, per ZIP installieren (ZIP-Slip-Schutz), löschen mit oder ohne Daten; abschaltbar per INHAUS_DISALLOW_FILE_MODS - Startseite komplett aus Kacheln; Plugin-Seiten als „slug::Seite“ - Version 0.3.0 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
cc0020458f
commit
28ef1e4a20
155 changed files with 2762 additions and 573 deletions
65
plugins-core/news/src/Http/Controllers/NewsController.php
Normal file
65
plugins-core/news/src/Http/Controllers/NewsController.php
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\News\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Inhaus\Plugins\News\Http\Resources\NewsPostResource;
|
||||
use Inhaus\Plugins\News\Models\NewsCategory;
|
||||
use Inhaus\Plugins\News\Models\NewsPost;
|
||||
|
||||
class NewsController extends Controller
|
||||
{
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$categories = NewsCategory::query()->orderBy('sort')->orderBy('name')->get(['id', 'name', 'slug']);
|
||||
$category = $categories->firstWhere('slug', $request->query('kategorie'));
|
||||
|
||||
$posts = NewsPost::query()
|
||||
->published()
|
||||
->with('category')
|
||||
->when($category, fn ($query) => $query->where('category_id', $category->id))
|
||||
->latest('published_at')
|
||||
->paginate(12)
|
||||
->withQueryString();
|
||||
|
||||
return Inertia::render('news::Index', [
|
||||
'posts' => NewsPostResource::collection($posts),
|
||||
'categories' => $categories->map(fn (NewsCategory $c) => ['name' => $c->name, 'slug' => $c->slug]),
|
||||
'activeCategory' => $category?->slug,
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(NewsPost $post): Response
|
||||
{
|
||||
abort_unless($post->isPublished(), 404);
|
||||
|
||||
$post->load(['category', 'author']);
|
||||
|
||||
return Inertia::render('news::Show', [
|
||||
'post' => [
|
||||
...(new NewsPostResource($post))->resolve(),
|
||||
'body_html' => $post->body_html,
|
||||
'author' => $post->author ? [
|
||||
'id' => $post->author->id,
|
||||
'name' => $post->author->name,
|
||||
'initials' => $post->author->initials,
|
||||
'job_title' => $post->author->job_title,
|
||||
'avatar_url' => $post->author->avatarUrl(96),
|
||||
] : null,
|
||||
],
|
||||
'related' => NewsPostResource::collection(
|
||||
NewsPost::query()
|
||||
->published()
|
||||
->with('category')
|
||||
->whereKeyNot($post->id)
|
||||
->when($post->category_id, fn ($query) => $query->where('category_id', $post->category_id))
|
||||
->latest('published_at')
|
||||
->limit(3)
|
||||
->get()
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
34
plugins-core/news/src/Http/Resources/NewsPostResource.php
Normal file
34
plugins-core/news/src/Http/Resources/NewsPostResource.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\News\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Inhaus\Plugins\News\Models\NewsPost;
|
||||
|
||||
/**
|
||||
* @mixin NewsPost
|
||||
*/
|
||||
class NewsPostResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'slug' => $this->slug,
|
||||
'teaser' => $this->teaser,
|
||||
'category' => $this->whenLoaded('category', fn () => $this->category ? [
|
||||
'name' => $this->category->name,
|
||||
'slug' => $this->category->slug,
|
||||
] : null),
|
||||
'cover_url' => $this->coverUrl('large'),
|
||||
'thumb_url' => $this->coverUrl('thumb'),
|
||||
'published_at' => $this->published_at?->toIso8601String(),
|
||||
'reading_minutes' => $this->reading_minutes,
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue