Search by

dominservice / laravel-theme-helper

dominservice

Manage Laravel themes, page metadata, hreflang, Schema.org JSON-LD, XML sitemaps and responsive image markup.

Package info

github.com/dominservice/laravel-theme-helper

pkg:composer/dominservice/laravel-theme-helper

Statistics

Installs: 8

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

4.0.0 2026-09-27 12:26 UTC

This package is auto-updated.

Last update: 2026-11-23 20:27:34 UTC


README

Laravel Theme Helper logo showing a browser window with interchangeable layout panels

Laravel Theme Helper manages frontend themes and generates page metadata, hreflang, Schema.org JSON-LD, sitemaps and responsive image markup for Laravel applications.

Developed by Mateusz Domin at Domin Software. It is the theme and metadata layer used by DominPress.

Packagist Latest Version Total Downloads Software License

Key Features

  • SEO and meta management,
  • asset registration and rendering,
  • breadcrumb and hreflang support,
  • JSON-LD / Schema.org generation,
  • sitemap and robots.txt generation helpers,
  • responsive image rendering with picture / AVIF / WebP / fallback support,
  • schema presets for common company and CMS pages,
  • theme registry and active theme selection,
  • public/admin theme context handling,
  • asset resolution for mix, vite, and static builds,
  • theme discovery through theme.json manifests.

It is designed to be the integration layer between your Laravel application and one or more frontend themes, while still providing the usual <head> and </body> helpers.

Table of contents

Requirements

  • PHP 8.4+
  • Laravel 13.32+
  • spatie/schema-org 5.x

The current 4.x line targets DominPress and Laravel 13. Laravel 10–12 and PHP 8.1–8.3 remain available through the previous 3.x line. PHP 8.4 is required by spatie/schema-org 5.

  • Optional: mcamara/laravel-localization

Installation

composer require dominservice/laravel-theme-helper

Optional hreflang integration:

composer require mcamara/laravel-localization

Publish config if you want to define themes globally:

php artisan vendor:publish --tag=config

This publishes:

  • config/theme-helper.php

Quick Start

use Dominservice\LaravelThemeHelper\Facades\Theme;

Theme::meta()
    ->setTitle('Laravel development', 'Domin Software')
    ->setDescription('PHP and Laravel development for businesses.')
    ->setCanonical(url()->current())
    ->setAuthor('Mateusz Domin')
    ->setGenerator('DominPress')
    ->setHttpEquiv('X-UA-Compatible', 'IE=edge')
    ->setIcons([
        'favicon' => asset('favicon.ico'),
        'manifest' => asset('site.webmanifest'),
        'theme_color' => '#0f172a',
    ]);

Theme::assets()->useTheme('public');

echo Theme::renderHead();
echo Theme::renderBodyEnd();

The generated head includes these tags. The canonical URL comes from the current request.

<meta name="description" content="PHP and Laravel development for businesses.">
<meta name="author" content="Mateusz Domin">
<meta name="generator" content="DominPress">

setIcons() also accepts apple_touch, icon, manifest, mask_icon, mask_color, ms_tile_image, ms_tile_color and theme_color. Use addMeta() and setHttpEquiv() to add other head tags.

Switch public theme dynamically:

Theme::useTheme('public-metronic', 'public');
Theme::assets()->useTheme('public');

Theme system

Contexts

The package supports theme contexts.

Typical usage:

  • admin
  • public

Rules are application-defined, but a common setup is:

  • admin always uses a fixed admin theme
  • public can use one of many declared themes

Theme config

Published config structure:

return [
    'contexts' => [
        'admin' => [
            'default_theme' => 'admin',
        ],
        'public' => [
            'default_theme' => 'public',
        ],
    ],

    'themes' => [
        'admin' => [
            'label' => 'Admin',
            'context' => 'admin',
            'driver' => 'static',
            'layout' => null,
            'view_path' => null,
            'entries' => [
                'css' => [],
                'js' => [],
            ],
            'meta' => [],
        ],
    ],

    'discovery' => [
        'enabled' => false,
        'manifest_filename' => 'theme.json',
        'scan_paths' => [],
    ],
];

Theme discovery with theme.json

The package can discover themes from one or more directories. This lets you keep your application-defined themes in config while also supporting uploaded or shipped themes described by a manifest.

Example config:

'discovery' => [
    'enabled' => true,
    'manifest_filename' => 'theme.json',
    'scan_paths' => [
        resource_path('themes'),
        base_path('themes'),
    ],
],

Example theme.json:

{
  "key": "classic",
  "label": "Classic",
  "context": "public",
  "driver": "mix",
  "layout": "themes.classic.layouts.app",
  "view_path": "resources/views/themes/classic",
  "manifest_path": "public/themes/classic/mix-manifest.json",
  "deploy_target": "public/themes/classic",
  "entries": {
    "css": ["themes/classic/app.css"],
    "js": ["themes/classic/app.js"]
  },
  "description": "Base public theme",
  "version": "1.0.0",
  "author": {
    "name": "Domin Software"
  },
  "settings": {
    "supports_upload": true
  }
}

If a theme key already exists in config, config has priority over discovered manifests. This makes discovery safe for local overrides.

Drivers

Supported asset drivers:

  • static
  • mix
  • vite

Theme switching

Theme::useTheme('public-metronic', 'public');
Theme::useTheme('admin', 'admin');

$theme = Theme::currentTheme('public');
$layout = $theme->layout();
$driver = $theme->driver();
$description = $theme->description();
$previewImage = $theme->previewImage();

Structured data

Multiple schema types on one page

Google supports multiple structured data items on the same page when they describe user-visible content on that page. This is useful for pages that need more than one schema type at once, for example:

  • Organization
  • WebSite
  • WebPage
  • BreadcrumbList
  • Product
  • Service
  • FAQPage

This package supports that pattern through @graph.

Simple example:

echo Theme::structuredGraph([
    [
        '@type' => 'Organization',
        'name' => 'Domin Software',
        'url' => 'https://example.com',
    ],
    [
        '@type' => 'WebPage',
        'name' => 'CRM systems',
        'url' => 'https://example.com/crm',
    ],
    [
        '@type' => 'BreadcrumbList',
        'itemListElement' => [
            [
                '@type' => 'ListItem',
                'position' => 1,
                'name' => 'Home',
                'item' => 'https://example.com',
            ],
        ],
    ],
]);

Schema collection API

$schemas = Theme::schemaCollection()
    ->organization([
        'name' => 'Domin Software',
        'url' => 'https://example.com',
    ])
    ->product([
        'name' => 'CMS Starter',
    ])
    ->service([
        'name' => 'CRM implementation',
        'serviceType' => 'Custom CRM development',
    ]);

echo Theme::structuredGraph($schemas);

This lets you output one graph that contains separate entities for organization data, product data, services, breadcrumbs or page-level metadata.

Schema presets

For common business pages you often want a repeatable graph instead of building every entity manually.

Available preset keys:

  • organization
  • website
  • home_page
  • web_page
  • service_page
  • product_page
  • faq_page

Example:

$schemas = Theme::schemaPreset('service_page', [
    'organization' => [
        'name' => 'Domin Software',
        'url' => 'https://example.com',
        'logo' => 'https://example.com/logo.png',
    ],
    'web_page' => [
        'name' => 'CRM systems',
        'url' => 'https://example.com/crm',
        'description' => 'Custom CRM systems for companies',
    ],
    'service' => [
        'name' => 'CRM implementation',
        'serviceType' => 'Custom CRM development',
    ],
    'breadcrumbs' => [
        ['@type' => 'ListItem', 'position' => 1, 'name' => 'Home', 'item' => 'https://example.com'],
        ['@type' => 'ListItem', 'position' => 2, 'name' => 'CRM', 'item' => 'https://example.com/crm'],
    ],
]);

echo Theme::structuredGraph($schemas);

Sitemap

The package includes a builder for XML sitemaps. It supports:

  • standard urlset,
  • sitemapindex,
  • image sitemap extensions,
  • alternate locale URLs through xhtml:link,
  • configurable default changefreq and priority.

Example:

$xml = Theme::sitemap()
    ->addUrl('https://example.com/', [
        'lastmod' => now(),
        'changefreq' => 'daily',
        'priority' => '1.0',
        'alternates' => [
            ['hreflang' => 'pl-PL', 'href' => 'https://example.com/'],
            ['hreflang' => 'en-US', 'href' => 'https://example.com/en'],
        ],
        'images' => [
            [
                'loc' => 'https://example.com/storage/hero.webp',
                'title' => 'Homepage hero image',
            ],
        ],
    ])
    ->renderUrlset();

For sitemap indexes:

$index = Theme::sitemap()
    ->addSitemap('https://example.com/sitemap-pages.xml')
    ->addSitemap('https://example.com/sitemap-blog.xml')
    ->renderIndex();

Robots.txt

The package also includes a builder for robots.txt.

Example:

$robots = Theme::robots()
    ->addGroup('*', allow: ['/'], disallow: ['/admin', '/login'])
    ->addSitemap('https://example.com/sitemap.xml')
    ->setHost('example.com')
    ->render();

Responsive images

The package includes a small renderer for SEO-friendly responsive images with modern formats.

Example using explicit <source> nodes:

echo Theme::images()->picture([
    [
        'type' => 'image/avif',
        'srcset' => asset('themes/classic/img/about.avif'),
        'media' => '(min-width: 768px)',
    ],
    [
        'type' => 'image/webp',
        'srcset' => asset('themes/classic/img/about.webp'),
    ],
], [
    'src' => asset('themes/classic/img/about.jpg'),
    'alt' => 'About section visual',
    'width' => 1400,
    'height' => 1040,
]);

Or using a simpler format map:

echo Theme::images()->pictureFromFormats([
    'avif' => asset('themes/classic/img/about.avif'),
    'webp' => asset('themes/classic/img/about.webp'),
    'jpg' => asset('themes/classic/img/about.jpg'),
], [
    'alt' => 'About section visual',
    'width' => 1400,
    'height' => 1040,
]);

API

Main facade methods:

Theme::meta();
Theme::assets();
Theme::breadcrumbs();
Theme::hreflang();
Theme::sitemap();
Theme::robots();
Theme::schemaPreset('home_page', [...]);
Theme::images();
Theme::registry();
Theme::contexts();
Theme::currentTheme('public');
Theme::useTheme('classic', 'public');
Theme::structured([...]);
Theme::schemaCollection();
Theme::structuredGraph([...]);
Theme::renderHead();
Theme::renderBodyEnd();

Blade integration

<head>
    {!! Theme::renderHead() !!}
</head>
<body>
    @yield('content')

    {!! Theme::renderBodyEnd() !!}
</body>

Helpers

Available helpers:

  • theme_structured_data(array $data, array $options = [])
  • theme_structured_graph(array $schemas, array $options = [])
  • theme_sitemap()
  • theme_robots()
  • theme_schema_preset(string $preset, array $data = [])
  • theme_picture(array $sources, array $imgAttributes = [], array $pictureAttributes = [])
  • theme_current_theme(string $context = 'public')
  • theme_current_layout(string $context = 'public')
  • theme_use(string $themeKey, ?string $context = null)

Deployment notes

Theme definitions can now also carry:

  • build_config_path
  • manifest_path
  • hot_file_path
  • deploy_target
  • source_path
  • preview_image
  • settings

This makes the package a good base for future theme upload, import/export and theme management panels without forcing a specific storage model today.

Testing

Run package tests:

vendor/bin/phpunit

Support

Report package issues on GitHub.

If this package helps you, you can buy me a coffee to support its maintenance.

Buy me a coffee on Ko-fi

License

MIT