承接 iz5clj/laravel-multi-theme 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

iz5clj/laravel-multi-theme

最新稳定版本:v1.0.4

Composer 安装命令:

composer require iz5clj/laravel-multi-theme

包简介

A Laravel package for multi-theme support with dynamic view path switching

README 文档

README

A Laravel package for multi-theme support with dynamic view path switching.

Installation

Via Composer (from Packagist after publishing)

composer require iz5clj/laravel-theme

Configuration

Publish the configuration file:

php artisan vendor:publish --tag=theme-config

This will create a config/theme.php file where you can set:

  • default - The default theme name
  • path - The base path where themes are located

Theme Structure

Create your themes in the configured path (default: resources/themes):

resources/themes/
├── my-theme/
│   └── views/
│       ├── welcome.blade.php
│       └── layouts/
│           └── app.blade.php
└── another-theme/
    └── views/
        └── welcome.blade.php

Usage

Via Middleware (Recommended)

Apply the theme middleware to routes or route groups:

// Single route
Route::get('/', function () {
    return view('welcome');
})->middleware('theme:my-theme');

// Route group
Route::middleware(['theme:my-theme'])->group(function () {
    Route::get('/', function () {
        return view('welcome');
    });
    
    Route::get('/about', function () {
        return view('about');
    });
});

Via Facade

use Michel\LaravelTheme\Facades\Theme;

// Set the theme
Theme::set('my-theme');

// Get current theme name
$currentTheme = Theme::get();

// Get theme asset URL
$cssUrl = Theme::asset('css/app.css');
// Returns: /themes/my-theme/css/app.css

// Check if a theme exists
if (Theme::exists('my-theme')) {
    // ...
}

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

In Blade Templates

The current theme name is shared with all views as $currentTheme:

<link href="{{ asset('themes/' . $currentTheme . '/css/app.css') }}" rel="stylesheet">

{{-- Or using the Theme facade --}}
<link href="{{ Theme::asset('css/app.css') }}" rel="stylesheet">

Theme Assets

Place your theme assets in the public directory:

public/themes/
├── my-theme/
│   ├── css/
│   │   └── app.css
│   ├── js/
│   │   └── app.js
│   └── images/
│       └── logo.png
└── another-theme/
    └── css/
        └── app.css

API Reference

ThemeService Methods

Method Description
set(string $theme) Set the active theme
get() Get the current theme name
asset(string $path) Generate URL for theme asset
exists(string $theme) Check if a theme exists
all() Get all available themes
getThemePath(string $theme = null) Get the full path to a theme's views
getBasePath() Get the base themes path
setBasePath(string $path) Set the base themes path

Environment Variables

Variable Description Default
THEME_DEFAULT The default theme name default

License

MIT License

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固