Installation
composer require apie/cms apie/cms-layout-graphite
apie/html-builders and a layout package (e.g., apie/cms-layout-graphite).Publish Config
php artisan vendor:publish --provider="Apie\Cms\CmsServiceProvider"
First Use Case: Basic Page Controller
use Apie\Cms\CmsController;
class MyPageController extends CmsController
{
public function index()
{
return $this->render('my-page', [
'title' => 'Welcome',
'content' => 'Hello, CMS!',
]);
}
}
routes/web.php:
Route::get('/my-page', [MyPageController::class, 'index']);
View Structure
resources/views/my-page.blade.php.Component-Based Rendering
Apie\HtmlBuilders to create reusable components:
use Apie\HtmlBuilders\HtmlBuilder;
class HeroComponent extends HtmlBuilder
{
public function render(): string
{
return $this->div(['class' => 'hero'])->h1('Welcome')->render();
}
}
return $this->render('home', [
'hero' => new HeroComponent(),
]);
Dynamic Route Handling
class BlogController extends CmsController
{
public function show($slug)
{
$post = Post::where('slug', $slug)->firstOrFail();
return $this->render('blog.post', compact('post'));
}
}
Route::get('/blog/{slug}', [BlogController::class, 'show']);
Layout Integration
app/Providers/AppServiceProvider:
use Apie\CmsLayoutGraphite\GraphiteLayout;
public function boot()
{
$this->app->singleton(GraphiteLayout::class, function () {
return new GraphiteLayout(config('cms.layout'));
});
}
Middleware for CMS Logic
Route::middleware(['auth', 'cms.cache'])->group(function () {
Route::get('/admin', [AdminController::class, 'index']);
});
Asset Management Use Laravel Mix/Vite to compile assets for CMS templates. Ensure the layout package supports your asset pipeline.
Database-Driven Pages
Store page configurations in a pages table and fetch dynamically:
$page = Page::where('slug', $slug)->with('components')->first();
return $this->render($page->template, $page->data);
API-Driven Content Fetch content from an API and pass to views:
$content = Http::get('https://api.example.com/content')->json();
return $this->render('api-page', ['content' => $content]);
Testing Use Laravel’s testing tools to mock CMS controllers:
$response = $this->get('/my-page');
$response->assertViewIs('my-page');
Missing Layout Package
Class 'Apie\CmsLayoutGraphite\GraphiteLayout' not found.apie/cms-layout-graphite (or another layout package) and publish its config.Route Caching Conflicts
php artisan route:cache.php artisan route:clear during development.Component Autoloading
app/Components or autoloaded via composer.json:
"autoload": {
"psr-4": {
"App\\Components\\": "app/Components/"
}
}
Blade Template Inheritance
@extends('layouts.graphite') in child templates.Middleware Priority
app/Http/Kernel.php under the correct group (e.g., web).View Debugging
.env:
DEBUG_BLADE_COMPILED=true
storage/framework/views.Route Debugging
php artisan route:list | grep cms
Component Debugging
dd((new HeroComponent())->render());
Layout Debugging
resources/views/layouts/partials/ to test changes without modifying the package.Custom Layouts
Apie\Cms\Contracts\Layout to create new layouts:
class MyLayout implements Layout
{
public function render(View $view): string
{
return $this->wrap($view, 'my-layout-template');
}
}
Dynamic Component Registration
$this->app->bind(HeroComponent::class, function () {
return new HeroComponent(config('cms.hero_settings'));
});
Event Listeners
Cms.PageRendering):
use Apie\Cms\Events\PageRendering;
Event::listen(PageRendering::class, function (PageRendering $event) {
$event->view->with('analytics', true);
});
Custom Middleware
class ValidateCmsContent
{
public function handle(Request $request, Closure $next)
{
if (!$request->user()->can('edit-cms')) {
abort(403);
}
return $next($request);
}
}
API Integration
use Apie\Cms\Contracts\CmsController;
class RemoteContentController extends CmsController
{
public function fetch()
{
$data = Http::get('https://api.example.com/data')->json();
return $this->render('remote-content', ['data' => $data]);
}
}
How can I help you explore Laravel packages today?