PHPackages                             ayra/laravel-themes - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ayra/laravel-themes

ActiveLibrary

ayra/laravel-themes
===================

A powerful theme management system for Laravel 12.x that helps you organize themes, layouts, assets, and widgets efficiently. Based on teepluss/theme with modern Laravel compatibility.

v2.0.0(9mo ago)49.6k↑120%2MITPHPPHP ^8.2

Since Sep 11Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/imajkumar/laravel-theme-management)[ Packagist](https://packagist.org/packages/ayra/laravel-themes)[ Docs](https://github.com/ayra/laravel-themes)[ RSS](/packages/ayra-laravel-themes/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (4)Used By (0)

Laravel Themes - Theme Management System for Laravel 12.x
=========================================================

[](#laravel-themes---theme-management-system-for-laravel-12x)

[![Latest Version on Packagist](https://camo.githubusercontent.com/583748d12797d52a8e313b6fcbd83e0231f5b254857adcc66b7d6bd02c46dc67/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f617972612f6c61726176656c2d7468656d65732e737667)](https://packagist.org/packages/ayra/laravel-themes)[![Total Downloads](https://camo.githubusercontent.com/4c75f693db299a9b40b5f384bc5743772466f640fe1f2c0a869724dce9a998f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f617972612f6c61726176656c2d7468656d65732e737667)](https://packagist.org/packages/ayra/laravel-themes)[![License](https://camo.githubusercontent.com/72b12ecfec50836ce50ffe979517faa2abd6712fed136d530b91924b71b06967/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f617972612f6c61726176656c2d7468656d65732e737667)](https://packagist.org/packages/ayra/laravel-themes)[![PHP Version](https://camo.githubusercontent.com/e27c361846d9d919a372afe4e37d02b1586c08edbead934ef1280cdbaf3358be/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f617972612f6c61726176656c2d7468656d65732e737667)](https://packagist.org/packages/ayra/laravel-themes)[![Laravel Version](https://camo.githubusercontent.com/32f514ec00d798b9f1c01ba9c87c75d6bbc336ffc927d8034e6953917fd02efa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f617972612f6c61726176656c2d7468656d65732f6c61726176656c2f6672616d65776f726b2e737667)](https://packagist.org/packages/ayra/laravel-themes)

A powerful and modern theme management system for Laravel 12.x that helps you organize themes, layouts, assets, and widgets efficiently. This package is based on [teepluss/theme](https://github.com/teepluss/laravel-theme/) but completely rewritten for modern Laravel compatibility.

✨ Features
----------

[](#-features)

- 🎨 **Multi-Theme Support**: Create and manage multiple themes with ease
- 🏗️ **Flexible Layouts**: Support for multiple layouts per theme
- 📦 **Asset Management**: Built-in asset pipeline with dependency management
- 🧩 **Widget System**: Create reusable widgets for your themes
- 🍞 **Breadcrumb Management**: Easy breadcrumb generation and customization
- 🔧 **Artisan Commands**: Powerful CLI tools for theme management
- 🎯 **Blade Directives**: Custom Blade directives for theme functionality
- 🚀 **Laravel 12 Ready**: Full compatibility with the latest Laravel version
- 📱 **Middleware Support**: Route-based theme switching
- 🎭 **Partial Views**: Modular view system with partials and sections
- 🔄 **Theme Switching**: Session/cookie-based theme persistence
- 📤 **Export/Import**: Backup and share themes easily
- 💾 **Auto-Backup**: Automatic theme backup with rotation
- 🌐 **CDN Support**: Built-in CDN integration for assets
- 📊 **Theme Statistics**: Get detailed theme information
- 👀 **Theme Preview**: Preview themes via URL parameters
- 🎛️ **Conditional Assets**: Load assets based on conditions
- 🔒 **Asset Integrity**: SRI support for security

🚀 Quick Start
-------------

[](#-quick-start)

### Requirements

[](#requirements)

- PHP 8.2 or higher
- Laravel 12.x

### Installation

[](#installation)

1. **Install via Composer:**

```
composer require ayra/laravel-themes
```

2. **Publish Configuration:**

```
php artisan vendor:publish --provider="Ayra\Theme\ThemeServiceProvider"
```

3. **Add to .env:**

```
APP_THEME=default
APP_THEME_LAYOUT=layout
APP_THEME_DIR=public/themes
```

4. **Create Your First Theme:**

```
php artisan theme:create default
```

📚 Documentation
---------------

[](#-documentation)

### Table of Contents

[](#table-of-contents)

- [Basic Usage](#basic-usage)
- [Theme Management](#theme-management)
- [Asset Management](#asset-management)
- [Layouts &amp; Views](#layouts--views)
- [Widgets](#widgets)
- [Breadcrumbs](#breadcrumbs)
- [Blade Directives](#blade-directives)
- [Configuration](#configuration)
- [Artisan Commands](#artisan-commands)
- [Advanced Features](#advanced-features)
- [Theme Switching](#theme-switching)
- [Export &amp; Import](#export--import)
- [Asset Optimization](#asset-optimization)
- [Theme Preview](#theme-preview)

🎯 Basic Usage
-------------

[](#-basic-usage)

### Setting Up a Theme

[](#setting-up-a-theme)

```
use Ayra\Theme\Facades\Theme;

// Set theme and layout
Theme::uses('default')->layout('main');

// Render a view
return Theme::view('home.index', ['title' => 'Welcome']);
```

### Controller Integration

[](#controller-integration)

```
namespace App\Http\Controllers;

use Ayra\Theme\Facades\Theme;

class HomeController extends Controller
{
    public function index()
    {
        Theme::uses('default')->layout('main');

        return Theme::view('home.index', [
            'title' => 'Welcome to Our Site',
            'description' => 'A beautiful theme-powered website'
        ]);
    }
}
```

🎨 Theme Management
------------------

[](#-theme-management)

### Creating Themes

[](#creating-themes)

```
# Create a new theme
php artisan theme:create my-theme

# Create theme with custom facade
php artisan theme:create my-theme --facade="MyTheme"

# Duplicate existing theme
php artisan theme:duplicate default new-theme

# List all themes
php artisan theme:list

# Remove a theme
php artisan theme:destroy my-theme
```

### Theme Structure

[](#theme-structure)

```
public/themes/my-theme/
├── assets/
│   ├── css/
│   ├── js/
│   └── img/
├── layouts/
├── partials/
│   └── sections/
├── views/
├── widgets/
├── theme.json
└── config.php

```

### Theme Manifest (theme.json)

[](#theme-manifest-themejson)

```
{
    "slug": "my-theme",
    "name": "My Beautiful Theme",
    "author": "Your Name",
    "email": "your@email.com",
    "description": "A stunning theme for Laravel applications",
    "web": "https://yoursite.com",
    "license": "MIT",
    "version": "1.0.0"
}
```

🔄 Theme Switching
-----------------

[](#-theme-switching)

### Session/Cookie Based Switching

[](#sessioncookie-based-switching)

```
// Switch theme and persist in session/cookie
Theme::switch('dark-theme', true);

// Switch theme for current request only
Theme::switch('light-theme', false);

// Get current theme from session/cookie
$currentTheme = Theme::getCurrentTheme();

// Check if specific theme is active
if (Theme::isActive('dark-theme')) {
    // Dark theme specific logic
}

// Clear theme session/cookie
Theme::clearTheme();
```

### Theme Preview via URL

[](#theme-preview-via-url)

```
// Preview theme: /home?theme=dark-theme
// Preview layout: /home?layout=mobile

// Add middleware to routes
Route::get('/home', function () {
    return Theme::view('home.index');
})->middleware('theme.preview');
```

### Route-Based Theme Switching

[](#route-based-theme-switching)

```
// Apply theme middleware to routes
Route::get('/admin', function () {
    return Theme::view('admin.dashboard');
})->middleware('theme:admin,admin-layout');

// Route groups with theme
Route::group(['middleware' => 'theme:mobile,mobile-layout'], function () {
    Route::get('/mobile', function () {
        return Theme::view('mobile.home');
    });
});
```

📤 Export &amp; Import
---------------------

[](#-export--import)

### Export Themes

[](#export-themes)

```
# Export theme to ZIP
php artisan theme:export default

# Export with custom output path
php artisan theme:export default --output=/path/to/backup.zip
```

### Import Themes

[](#import-themes)

```
# Import theme from ZIP
php artisan theme:import /path/to/theme.zip

# Import with custom name
php artisan theme:import /path/to/theme.zip --name="my-custom-theme"

# Force import (overwrite existing)
php artisan theme:import /path/to/theme.zip --force
```

### Auto-Backup System

[](#auto-backup-system)

```
# Create backup with automatic rotation
php artisan theme:backup default

# Keep specific number of backups
php artisan theme:backup default --keep=10
```

📦 Asset Management
------------------

[](#-asset-management)

### Basic Asset Management

[](#basic-asset-management)

```
// In your theme config.php or controller
$asset = Theme::asset();

// Add CSS and JS files
$asset->add('bootstrap', 'css/bootstrap.min.css');
$asset->add('jquery', 'js/jquery.min.js', ['bootstrap']);

// Theme-specific assets
$asset->themePath()->add('custom', 'css/custom.css');

// External CDN assets
$asset->add('fontawesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css');
```

### Advanced Asset Features

[](#advanced-asset-features)

```
// CDN Support
$asset->enableCdn('https://cdn.example.com');
$asset->add('bootstrap', 'css/bootstrap.min.css');
$asset->disableCdn();

// Asset Versioning
$asset->addVersioned('app', 'js/app.js');
$asset->addVersioned('style', 'css/style.css', [], '2.0.0');

// Conditional Assets
$asset->addConditional('mobile', 'mobile-css', 'css/mobile.css');
$asset->addConditional('desktop', 'desktop-css', 'css/desktop.css');

// Asset Integrity (SRI)
$asset->addWithIntegrity('bootstrap', 'css/bootstrap.min.css', 'sha384-...');

// Asset Optimization
$asset->optimize(true); // Use minified versions in production
```

### Asset Containers

[](#asset-containers)

```
// Create named containers
$asset->container('footer')->add('footer-script', 'js/footer.js');

// Render specific containers
@scripts('footer')
```

### Inline Assets

[](#inline-assets)

```
// Inline CSS
$asset->writeStyle('custom-style', 'body { background: #f0f0f0; }');

// Inline JavaScript
$asset->writeScript('custom-script', 'console.log("Hello World!");');
```

🏗️ Layouts &amp; Views
----------------------

[](#️-layouts--views)

### Layout System

[](#layout-system)

```
// Set layout
Theme::layout('admin');

// Multiple layouts
Theme::layout('mobile')->uses('mobile-theme');
```

### View Rendering

[](#view-rendering)

```
// Basic view
Theme::view('home.index', $data);

// With specific theme and layout
Theme::uses('admin')->layout('dashboard')->view('admin.dashboard', $data);

// Scope to theme directory
Theme::scope('home.index', $data)->render();

// Watch both theme and app views
Theme::watch('home.index', $data)->render();
```

### Partials

[](#partials)

```
// Render partial
@partial('header', ['title' => 'Page Header'])

// Sections (from partials/sections/)
@sections('main')

// Partial with layout context
Theme::partialWithLayout('sidebar', ['menu' => $menu]);
```

🧩 Widgets
---------

[](#-widgets)

### Creating Widgets

[](#creating-widgets)

```
# Global widget
php artisan theme:widget UserProfile --global

# Theme-specific widget
php artisan theme:widget UserProfile default
```

### Widget Class

[](#widget-class)

```
namespace App\Widgets;

use Ayra\Theme\Widget;

class WidgetUserProfile extends Widget
{
    public function render($data = [])
    {
        return view('widgets.user-profile', $data);
    }
}
```

### Using Widgets

[](#using-widgets)

```
// In Blade templates
@widget('user-profile', ['user' => $user])

// In PHP
Theme::widget('user-profile', ['user' => $user])->render();
```

🍞 Breadcrumbs
-------------

[](#-breadcrumbs)

### Creating Breadcrumbs

[](#creating-breadcrumbs)

```
// Simple breadcrumb
Theme::breadcrumb()
    ->add('Home', '/')
    ->add('Products', '/products')
    ->add('Category', '/products/category');

// Array-based
Theme::breadcrumb()->add([
    ['label' => 'Home', 'url' => '/'],
    ['label' => 'Products', 'url' => '/products'],
    ['label' => 'Category', 'url' => '/products/category']
]);
```

### Custom Templates

[](#custom-templates)

```
// Set custom template
Theme::breadcrumb()->setTemplate('

            @foreach($crumbs as $i => $crumb)
                @if($i != (count($crumbs) - 1))

                        {{ $crumb["label"] }}

                @else
                    {{ $crumb["label"] }}
                @endif
            @endforeach

');

// Render breadcrumbs
{!! Theme::breadcrumb()->render() !!}
```

🎭 Blade Directives
------------------

[](#-blade-directives)

### Available Directives

[](#available-directives)

```
// Theme data
@get('title')
@getIfHas('description', 'Default description')

// Partials and sections
@partial('header', ['title' => 'Header'])
@sections('main')

// Content
@content()

// Assets
@styles()
@scripts()
@styles('footer')
@scripts('footer')

// Widgets
@widget('user-profile', ['user' => $user])

// Utilities
@protect('email@example.com')
@dd('Debug info')
@d('Debug info')
@dv()
```

🛠️ Helper Functions
-------------------

[](#️-helper-functions)

### Date &amp; Time Helpers

[](#date--time-helpers)

```
// Format dates
format_date('2024-01-15', 'F j, Y') // January 15, 2024
human_date('2024-01-15') // 2 months ago
time_ago('2024-01-15') // 2 months ago

// Date checks
is_weekend('2024-01-15') // false
is_business_day('2024-01-15') // true

// Age calculation
get_age('1990-05-20') // 33
```

### Formatting Helpers

[](#formatting-helpers)

```
// Number formatting
format_bytes(1024) // 1 KB
format_number(1500) // 1.5K
format_currency(99.99, 'USD') // $99.99

// Text formatting
slugify('Hello World!') // hello-world
truncate('Long text here...', 10) // Long text...
word_limit('Many words in this sentence', 5) // Many words in this...

// Search highlighting
highlight_search('Hello World', 'world') // Hello World
```

### Security &amp; Privacy Helpers

[](#security--privacy-helpers)

```
// Password & token generation
generate_password(16, true) // Random secure password
generate_token(32) // Random hex token

// Data masking
mask_email('user@example.com') // us**@ex***.com
mask_phone('+1-555-123-4567') // +1-5**-***-4567

// Email protection
protectEmail('user@example.com') // JavaScript-protected email link
```

### Device &amp; Browser Detection

[](#device--browser-detection)

```
// Device type
is_mobile() // true/false
is_tablet() // true/false
is_desktop() // true/false

// Browser information
$browser = get_browser_info();
// Returns: ['browser' => 'Chrome', 'version' => '120.0', 'os' => 'Windows']

// Client information
get_client_ip() // Client IP address
get_country_code() // Country code from IP
```

### File &amp; Media Helpers

[](#file--media-helpers)

```
// File validation
is_image('photo.jpg') // true
is_video('movie.mp4') // true
is_audio('song.mp3') // true

// File utilities
sanitize_filename('My File (1).pdf') // My_File_1.pdf
get_file_extension('document.pdf') // pdf
get_file_size('/path/to/file') // 2.5 MB
```

### Validation Helpers

[](#validation-helpers)

```
// Input validation
validate_email('user@example.com') // true
validate_url('https://example.com') // true
validate_ip('192.168.1.1') // true
```

### UI &amp; Design Helpers

[](#ui--design-helpers)

```
// Colors
get_random_color() // #a1b2c3
get_contrast_color('#ffffff') // #000000

// Emojis
get_emoji('smile') // 😊
get_emoji('heart') // ❤️
get_flag_emoji('US') // 🇺🇸

// Gravatar
get_gravatar_url('user@example.com', 200) // Gravatar URL
```

### Testing &amp; Development Helpers

[](#testing--development-helpers)

```
// Random test data
get_random_name() // John Smith
get_random_email() // john.smith@gmail.com
get_random_company() // TechCorp
get_random_phone() // +1-555-123-4567
get_random_address() // 123 Main St, New York, NY 10001
get_random_website() // https://www.example.com

// Random quotes
get_random_quote() // Inspirational quote
```

### SEO &amp; Meta Helpers

[](#seo--meta-helpers)

```
// Basic meta tags
meta_init() // Common meta tags

// Custom meta tags
meta_tags([
    'title' => 'Page Title',
    'description' => 'Page description',
    'keywords' => 'laravel, themes'
])

// SEO tags
seo_tags(
    'Page Title',
    'Page description',
    'keywords',
    'Author Name',
    'https://example.com/image.jpg',
    'https://example.com/page'
)
```

### Utility Helpers

[](#utility-helpers)

```
// Ordinal numbers
get_ordinal(1) // 1st
get_ordinal(2) // 2nd
get_ordinal(3) // 3rd

// Pluralization
get_plural('category', 1) // category
get_plural('category', 5) // categories

// QR Code & Barcode (requires additional libraries)
generate_qr_code('https://example.com')
generate_barcode('123456789')
```

🚀 Advanced Features
-------------------

[](#-advanced-features)

### Theme Statistics

[](#theme-statistics)

```
// Get all available themes
$themes = Theme::getAvailableThemes();

// Get theme statistics
$stats = Theme::getThemeStats('default');
// Returns: ['views' => 15, 'partials' => 8, 'assets' => 12, 'layouts' => 3, 'widgets' => 5]

// Check theme existence
if (Theme::exists('my-theme')) {
    // Theme exists
}
```

### Theme Preview URLs

[](#theme-preview-urls)

```
// Generate preview URLs
$previewUrl = Theme::getPreviewUrl('dark-theme', '/home');
// Returns: http://yoursite.com/home?theme=dark-theme

$layoutPreviewUrl = Theme::getPreviewUrl('default', '/admin', 'admin-layout');
// Returns: http://yoursite.com/admin?theme=default&layout=admin-layout
```

### Conditional Asset Loading

[](#conditional-asset-loading)

```
// Load assets based on conditions
$asset->addConditional('mobile', 'mobile-css', 'css/mobile.css');
$asset->addConditional('desktop', 'desktop-css', 'css/desktop.css');

// In your Blade templates
@if(request()->isMobile())
    @foreach(Theme::asset()->getConditionalAssets('mobile') as $name => $asset)

    @endforeach
@endif
```

### Asset Optimization

[](#asset-optimization)

```
// Enable optimization for production
if (app()->environment('production')) {
    Theme::asset()->optimize(true);
}

// This will automatically use minified versions if they exist
// css/style.css → css/min/style.min.css
```

### Theme Switching Examples

[](#theme-switching-examples)

```
// Switch theme with persistence
Theme::switch('dark-theme', true);

// Switch theme for current request only
Theme::switch('light-theme', false);

// Check current theme
$currentTheme = Theme::getCurrentTheme();

// Check if specific theme is active
if (Theme::isActive('dark-theme')) {
    // Dark theme specific logic
}
```

### Export/Import Examples

[](#exportimport-examples)

```
# Export theme
php artisan theme:export default --output=/backups/theme.zip

# Import theme
php artisan theme:import /backups/theme.zip --name="restored-theme" --force

# Create backup with rotation
php artisan theme:backup default --keep=10
```

### Advanced Asset Management

[](#advanced-asset-management)

```
// CDN Support
$asset->enableCdn('https://cdn.example.com');
$asset->add('bootstrap', 'css/bootstrap.min.css');

// Asset Versioning
$asset->addVersioned('app', 'js/app.js');
$asset->addVersioned('style', 'css/style.css', [], '2.0.0');

// Asset Integrity (SRI)
$asset->addWithIntegrity('bootstrap', 'css/bootstrap.min.css', 'sha384-...');

// Conditional Assets
$asset->addConditional('mobile', 'mobile-css', 'css/mobile.css');
$asset->addConditional('desktop', 'desktop-css', 'css/desktop.css');
```

📚 Complete Helper Function Reference
------------------------------------

[](#-complete-helper-function-reference)

### Date &amp; Time Functions

[](#date--time-functions)

- `format_date($date, $format, $timezone)` - Format date with custom format
- `human_date($date)` - Get human readable date
- `time_ago($timestamp)` - Get time ago from timestamp
- `is_weekend($date)` - Check if date is weekend
- `is_business_day($date)` - Check if date is business day
- `get_age($birthDate)` - Calculate age from birth date

### Formatting Functions

[](#formatting-functions)

- `format_bytes($bytes, $precision)` - Format bytes to human readable
- `format_number($number, $precision)` - Format number with abbreviations
- `format_currency($amount, $currency, $locale)` - Format currency
- `slugify($text, $separator)` - Create URL-friendly slug
- `truncate($text, $length, $ending)` - Truncate text to length
- `word_limit($text, $limit, $ending)` - Limit text to word count
- `highlight_search($text, $search, $highlight)` - Highlight search terms

### Security Functions

[](#security-functions)

- `generate_password($length, $special_chars)` - Generate random password
- `generate_token($length)` - Generate random token
- `mask_email($email, $mask)` - Mask email for privacy
- `mask_phone($phone, $mask)` - Mask phone for privacy
- `protectEmail($email)` - Protect email from bots

### Device Detection Functions

[](#device-detection-functions)

- `is_mobile()` - Check if request is from mobile
- `is_tablet()` - Check if request is from tablet
- `is_desktop()` - Check if request is from desktop
- `get_browser_info()` - Get browser information
- `get_client_ip()` - Get client IP address
- `get_country_code($ip)` - Get country code from IP

### File Functions

[](#file-functions)

- `sanitize_filename($filename)` - Sanitize filename
- `get_file_extension($filename)` - Get file extension
- `is_image($filename)` - Check if file is image
- `is_video($filename)` - Check if file is video
- `is_audio($filename)` - Check if file is audio
- `get_file_size($filepath)` - Get file size

### Validation Functions

[](#validation-functions)

- `validate_email($email)` - Validate email address
- `validate_url($url)` - Validate URL
- `validate_ip($ip)` - Validate IP address

### UI Functions

[](#ui-functions)

- `get_random_color()` - Get random color
- `get_contrast_color($hexColor)` - Get contrasting color
- `get_emoji($name)` - Get emoji by name
- `get_flag_emoji($countryCode)` - Get country flag emoji
- `get_gravatar_url($email, $size)` - Get Gravatar URL

### Utility Functions

[](#utility-functions)

- `get_ordinal($number)` - Get ordinal suffix
- `get_plural($singular, $count)` - Get plural form
- `get_random_quote()` - Get random inspirational quote
- `get_random_name()` - Get random name for testing
- `get_random_email()` - Get random email for testing
- `get_random_company()` - Get random company for testing

### SEO Functions

[](#seo-functions)

- `meta_init()` - Print common meta tags
- `meta_tags($tags)` - Generate meta tags from array
- `seo_tags($title, $description, $keywords, $author, $image, $url)` - Generate SEO meta tags

🎯 Usage Examples in Themes
--------------------------

[](#-usage-examples-in-themes)

### In Theme Configuration

[](#in-theme-configuration)

```
// public/themes/my-theme/config.php
return [
    'events' => [
        'before' => function($theme) {
            // Set dynamic title with current date
            $theme->setTitle('My Theme - ' . format_date(now(), 'F Y'));

            // Set meta tags
            $theme->setDescription('A beautiful theme created on ' . human_date(now()));

            // Add conditional assets based on device
            if (is_mobile()) {
                $theme->asset()->add('mobile-css', 'css/mobile.css');
            }
        },
        'asset' => function($asset) {
            // Add versioned assets
            $asset->addVersioned('main', 'css/main.css');
            $asset->addVersioned('app', 'js/app.js');

            // Add CDN assets
            $asset->enableCdn('https://cdn.example.com');
            $asset->add('bootstrap', 'css/bootstrap.min.css');
            $asset->disableCdn();
        }
    ]
];
```

### In Blade Templates

[](#in-blade-templates)

```
{{-- layouts/main.blade.php --}}
DOCTYPE html>

    {!! meta_init() !!}
    {!! seo_tags($title ?? 'My Site', $description ?? 'Welcome', $keywords ?? '') !!}

    @styles()

    {{-- Conditional assets --}}
    @if(is_mobile())

    @endif

        {{ $title ?? 'Welcome' }}
        Last updated: {{ human_date($lastUpdated) }}

        {{-- Device-specific content --}}
        @if(is_mobile())
            Mobile Navigation
        @elseif(is_tablet())
            Tablet Navigation
        @else
            Desktop Navigation
        @endif

        @content()

        &copy; {{ date('Y') }} {{ get_random_company() }}
        Generated in {{ format_bytes(memory_get_peak_usage()) }}

    @scripts()

```

### In Controllers

[](#in-controllers)

```
namespace App\Http\Controllers;

use Ayra\Theme\Facades\Theme;

class HomeController extends Controller
{
    public function index()
    {
        // Switch theme based on user preference
        if (request()->has('theme')) {
            Theme::switch(request()->get('theme'), true);
        }

        // Get theme statistics
        $stats = Theme::getThemeStats(Theme::getCurrentTheme());

        // Prepare data with helper functions
        $data = [
            'title' => 'Welcome to ' . get_random_company(),
            'description' => 'A beautiful site created on ' . human_date(now()),
            'stats' => $stats,
            'isMobile' => is_mobile(),
            'browserInfo' => get_browser_info(),
            'randomQuote' => get_random_quote()
        ];

        return Theme::view('home.index', $data);
    }
}
```

This comprehensive set of helper functions makes your Laravel Themes package incredibly powerful and user-friendly! Users can now build sophisticated themes with minimal custom code, using these built-in utilities for common tasks.

🎓 How to Use - Complete Tutorial
--------------------------------

[](#-how-to-use---complete-tutorial)

### 🚀 Getting Started - Step by Step

[](#-getting-started---step-by-step)

#### 1. **Installation &amp; Setup**

[](#1-installation--setup)

```
# Install the package
composer require ayra/laravel-themes

# Publish configuration
php artisan vendor:publish --provider="Ayra\Theme\ThemeServiceProvider"

# Add to .env file
echo "APP_THEME=default" >> .env
echo "APP_THEME_LAYOUT=main" >> .env
echo "APP_THEME_DIR=public/themes" >> .env

# Create your first theme
php artisan theme:create default
```

#### 2. **Basic Theme Structure**

[](#2-basic-theme-structure)

After running `php artisan theme:create default`, you'll have:

```
public/themes/default/
├── assets/
│   ├── css/
│   │   └── style.css
│   ├── js/
│   │   └── script.js
│   └── img/
├── layouts/
│   └── layout.blade.php
├── partials/
│   ├── header.blade.php
│   ├── footer.blade.php
│   └── sections/
│       └── main.blade.php
├── views/
│   └── index.blade.php
├── widgets/
├── theme.json
└── config.php

```

#### 3. **Create Your First Layout**

[](#3-create-your-first-layout)

```
{{-- public/themes/default/layouts/layout.blade.php --}}
DOCTYPE html>

    {{ Theme::get('title', 'My Website') }}

    {!! meta_init() !!}
    @styles()

    @partial('header')

        @content()

    @partial('footer')

    @scripts()

```

#### 4. **Create Header Partial**

[](#4-create-header-partial)

```
{{-- public/themes/default/partials/header.blade.php --}}

            {{ Theme::get('site_name', 'My Site') }}

            Home
            About
            Contact

        {{-- Device-specific navigation --}}
        @if(is_mobile())
            ☰
        @endif

    {{-- Breadcrumbs --}}
    {!! Theme::breadcrumb()->render() !!}

```

#### 5. **Create Main Content Section**

[](#5-create-main-content-section)

```
{{-- public/themes/default/partials/sections/main.blade.php --}}

        {{ $title ?? 'Welcome' }}

        @if(isset($description))
            {{ $description }}
        @endif

        {{-- Show last updated time --}}
        @if(isset($lastUpdated))

                Last updated: {{ human_date($lastUpdated) }}

        @endif

        {{-- Content area --}}

            @yield('content')

```

#### 6. **Create Footer Partial**

[](#6-create-footer-partial)

```
{{-- public/themes/default/partials/footer.blade.php --}}

                About Us
                {{ Theme::get('footer_about', 'A beautiful website built with Laravel Themes.') }}

                Contact
                Email: {!! protectEmail('contact@example.com') !!}
                Phone: {{ mask_phone('+1-555-123-4567') }}

                Quick Links

                    Privacy Policy
                    Terms of Service

            &copy; {{ date('Y') }} {{ get_random_company() }}. All rights reserved.
            Generated in {{ format_bytes(memory_get_peak_usage()) }}

```

#### 7. **Create Your First View**

[](#7-create-your-first-view)

```
{{-- public/themes/default/views/index.blade.php --}}
@extends('theme::layouts.layout')

@section('content')

    {{ $title ?? 'Welcome to Our Site' }}

    @if(isset($description))
        {{ $description }}
    @endif

    {{-- Show random quote --}}

        "{{ get_random_quote() }}"

    {{-- Device-specific content --}}
    @if(is_mobile())

            Mobile Optimized
            This site is optimized for mobile devices!

    @elseif(is_tablet())

            Tablet Friendly
            Perfect for tablet users!

    @else

            Desktop Experience
            Full desktop experience with advanced features!

    @endif

    {{-- Theme statistics --}}
    @if(isset($stats))

            Theme Statistics

                Views: {{ $stats['views'] }}
                Partials: {{ $stats['partials'] }}
                Assets: {{ $stats['assets'] }}
                Layouts: {{ $stats['layouts'] }}
                Widgets: {{ $stats['widgets'] }}

    @endif

@endsection
```

#### 8. **Configure Your Theme**

[](#8-configure-your-theme)

```
{{-- public/themes/default/config.php --}}
