Add CMS module
Static content pages (CmsPage) manageable from a new Filament resource and readable via a public API endpoint. Wired into the admin panel with its own CmsPlugin and "CMS" navigation group.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Cms\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Modules\Cms\Http\Resources\CmsPageResource;
|
||||
use Modules\Cms\Models\CmsPage;
|
||||
|
||||
class CmsPageController extends Controller
|
||||
{
|
||||
public function index(): AnonymousResourceCollection
|
||||
{
|
||||
return CmsPageResource::collection(
|
||||
CmsPage::query()->where('is_active', true)->paginate()
|
||||
);
|
||||
}
|
||||
|
||||
public function show(string $page): CmsPageResource
|
||||
{
|
||||
$cmsPage = CmsPage::query()
|
||||
->where('page', $page)
|
||||
->where('is_active', true)
|
||||
->firstOrFail();
|
||||
|
||||
return new CmsPageResource($cmsPage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Cms\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CmsPageResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'page' => $this->page,
|
||||
'title' => $this->title,
|
||||
'mm_title' => $this->mm_title,
|
||||
'meta_tags' => $this->meta_tags,
|
||||
'meta_keywords' => $this->meta_keywords,
|
||||
'content' => $this->content,
|
||||
'mm_content' => $this->mm_content,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user