Installation
composer require appdezign/lara-pro-demo-theme
php artisan vendor:publish --provider="Appdezign\LaraProDemoTheme\LaraProDemoThemeServiceProvider" --tag="public"
php artisan vendor:publish --provider="Appdezign\LaraProDemoTheme\LaraProDemoThemeServiceProvider" --tag="config"
Enable the Theme
config/cms.php under themes:
'themes' => [
'demo' => [
'name' => 'Demo Theme',
'path' => 'vendor/appdezign/lara-pro-demo-theme',
'is_child' => true,
'parent' => 'base', // Parent theme (Base Theme)
],
],
.env:
CMS_THEME=demo
First Use Case: Displaying a Page
use Appdezign\CMS\Facades\CMS;
$page = CMS::page('home');
return view('demo::pages.home', compact('page'));
@extends('demo::layouts.app')
Child Theme Inheritance
resources/views/vendor/demo/ (or resources/views/demo/ if using a custom path).layouts/app.blade.php:
cp vendor/appdezign/lara-pro-demo-theme/resources/views/layouts/app.blade.php resources/views/demo/layouts/
Dynamic Content Rendering
{!! $page->blocks()->where('name', 'hero')->render() !!}
$heroBlock = $page->blocks()->where('name', 'hero')->first();
$heroBlock->data['title']; // Custom field access
Asset Management
// resources/js/demo/app.js
require('./vendor/demo');
@vite(['resources/js/demo/app.js', 'resources/css/demo/app.css'])
Theme-Specific Routes
routes/demo.php (if using a custom path):
Route::get('/custom-route', [DemoController::class, 'index']);
AppServiceProvider:
public function boot()
{
if (config('cms.theme') === 'demo') {
$this->loadRoutesFrom(__DIR__.'/../routes/demo.php');
}
}
Configuration Overrides
config/demo.php:
return [
'settings' => [
'default_color' => '#ff0000', // Override parent config
],
];
config('demo.settings.default_color');
vite.config.js to resolve demo theme assets:
resolve: {
alias: {
'@demo': path.resolve(__dirname, 'resources/js/demo'),
},
},
@stack('demo-scripts') in layouts/app.blade.php to inject theme-specific JS:
@stack('demo-scripts')
<img src="{{ $block->data['image']->url }}" alt="{{ $block->data['image_alt'] }}">
Parent Theme Dependencies
composer require appdezign/lara-pro-base-theme
config/cms.php for the correct parent key.Asset Path Conflicts
demo-app.js instead of app.js).php artisan cache:clear
php artisan view:clear
npm run dev
Block Data Serialization
json_encode/json_decode for complex data:
$data = json_decode($block->data['custom_field'], true);
AppServiceProvider:
CMS::block('hero')->validate(function ($data) {
return validator($data, ['title' => 'required|string']);
});
Theme Switching
$theme = env('CMS_THEME', 'demo');
demo:: prefix).
@extends('demo::layouts.app') <!-- Correct -->
@extends('layouts.app') <!-- Wrong (unless published) -->
php artisan config:clear to reset cached config after changes.php artisan route:list | grep demo
Custom Blocks
php artisan vendor:publish --tag="cms-blocks"
AppServiceProvider:
CMS::block('custom_block')->view('demo::blocks.custom');
Theme Events
demo.theme.ready):
event(new DemoThemeReady);
EventServiceProvider:
protected $listen = [
'Appdezign\LaraProDemoTheme\Events\DemoThemeReady' => [
DemoThemeListener::class,
],
];
API Endpoints
routes/api.php:
Route::prefix('demo')->group(function () {
Route::get('/data', [DemoApiController::class, 'fetchData']);
});
Route::middleware(['theme:demo'])->group(function () { ... });
php artisan cms:demo (if available) to reset the demo theme to default state.document.addEventListener('alpine:init', () => {
Alpine.data('demoAssets', () => ({
load() {
this.$nextTick(() => {
require('./vendor/demo/assets');
});
},
}));
});
$this->app->singleton('cms.theme', function () {
return 'demo';
});
How can I help you explore Laravel packages today?