定制 creativesofttechsolutions/laravelthemes 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

creativesofttechsolutions/laravelthemes

最新稳定版本:v1.0.0

Composer 安装命令:

composer require creativesofttechsolutions/laravelthemes

包简介

Theme Manager for Laravel

README 文档

README

This is a Laravel theme and asset management package. You can easily integrate this package with any Laravel based project.

Features

  • Custom theme path
  • Override theme
  • Parent theme support
  • Unlimited Parent view finding
  • Asset Finding
  • Theme translator support
  • Multiple theme config extension
  • Multiple theme changelog extension
  • Artisan console commands
  • Theme enable only Specific route via middleware
  • Almost everything customizable
  • Also Laravel 5.5 to Laravel 10 Supported

🛠 Installation

To install the creativesofttechsolutions/laravelthemes package, use Composer:

composer require creativesofttechsolutions/laravelthemes

Configuration

Run this command in your terminal to publish this package resources:

php artisan vendor:publish --provider="CreativeSoftTechSolutions\LaravelThemes\Providers\ThemeServiceProvider"

Artisan Command

Run this command in your terminal from your project directory.

Create a theme directory:

php artisan theme:create your_theme_name


 What is theme title?:
 >

 What is theme description? []:
 >

 What is theme author name? []:
 >

 What is theme version? []:
 >

 Any parent theme? (yes/no) [no]:
 > y

 What is parent theme name?:
 >

List of all themes:

php artisan theme:list

+----------+--------------+---------+----------+
| Name     | Author       | Version | Parent   |
+----------+--------------+---------+----------+
| themeone | Vaneet Joshi | 1.1.0   |          |
| themetwo | Vaneet Joshi | 1.0.0   | themeone |
+----------+--------------+---------+----------+

Example folder structure:

- app/
- ..
- ..
- Themes/
    - themeone/
        - assets
            - css
                - app.css
            - img
            - js
        - views/
            - layouts
                - master.blade.php
            - welcome.blade.php
        - theme.json
     - themetwo/

Then run theme:create command which describe above.

Now Please see the API List Doc.

View Finding Flow:

Suppose you want find welcome.blade.php

 - At first check your active theme
 - If `welcome.blade.php not found in active theme then search parent recursively
 - If `welcome.blade.php not found in parents theme then search laravel default view folder resources/views

API List

set

For switching current theme you can use set method.

Themes::set('theme-name');

get

For getting current theme details you can use get method:

Themes::get(); // return Array

You can also get particular theme details:

Themes::get('theme-name'); // return Array
Themes::get('theme-name', true); // return Collection

current

Retrieve current theme's name:

Themes::current(); // return string

all

Retrieve all theme information:

Themes::all(); // return Array

has

For getting whether the theme exists or not:

Themes::has(); // return bool

getThemeInfo

For info about the specified theme:

$themeInfo = Themes::getThemeInfo('theme-name'); // return Collection

$themeName = $themeInfo->get('name');
// or
$themeName = $themeInfo['name'];

Also fallback support:

$themeInfo = Themes::getThemeInfo('theme-name'); // return Collection

$themeName = $themeInfo->get('changelog.versions');
// or
$themeName = $themeInfo['changelog.versions'];
// or you can also call like as multi dimension
$themeName = $themeInfo['changelog']['versions'];

assets

For binding theme assets you can use the assets method:

Themes::assets('your_asset_path'); // return string

It's generated at BASE_URL/theme_roots/your_active_theme_name/assets/your_asset_path

If your_asset_path does not exist then it's find to active theme immediate parent assets folder. Look like BASE_URL/theme_roots/your_active_theme_parent_name/assets/your_asset_path

When using helper you can also get assets path:

themes('your_asset_path'); // return string

If you want to bind specific theme assets:

Themes::assets('your_theme_name:your_asset_path'); // return string
// or
themes('your_theme_name:your_asset_path'); // return string

Suppose you want to bind app.css in your blade. Then below code can be applicable:

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

Specific theme assets:

<link rel="stylesheet" href="{{ themes('your_theme_name:app.css') }}">

If you want to bind specific theme assets:

echo Themes::lang('your_theme_name::your_asset_path'); // return string
// or
echo lang('your_theme_name::your_asset_path'); // return string

How to use in Route

Route::get('/', function () {
    Themes::set('your_theme_name');
    return view('welcome');
});

This will firstly check if there is a welcome.blade.php in current theme directory. If none is found then it checks parent theme, and finally falls back to default Laravel views location.

If you want to specific theme view:

Route::get('/', function () {
    Themes::set('your_theme_name');
    return view('your_theme_name::welcome');
});

Set theme using route middleware

A helper middleware is included out of the box if you want to define a theme per route. To use it:

First register it in bootstrap/app.php:

->withMiddleware(function (Middleware $middleware): void {
    \CreativeSoftTechSolutions\LaravelThemes\Middleware\RouteMiddleware::class,
})

Now you can apply the middleware to a route or route-group. Eg:

Route::group(['prefix' => 'admin', 'middleware'=>'theme:Your_theme_name'], function() {
    // ... Add your routes here
    // The Your_theme_name will be applied.
});

Set theme using web middleware

A helper middleware is included out of the box if you want to define a theme per route. To use it:

First register it in app\Http\Kernel.php:

->withMiddleware(function (Middleware $middleware): void {
    \CreativeSoftTechSolutions\LaravelThemes\Middleware\WebMiddleware::class,
})

Theme set from config/themes.php .

Then in your controller you can call your view as you would normally do:

return view('home');  // This will load the home.blade.php from the the folder you set in your `config/theme.php`

Dependency Injection

You can also inject theme instance using ThemeContract, eg:

use CreativeSoftTechSolutions\LaravelThemes\Contracts\ThemeContract;

private $theme;

public function __construct(ThemeContract $theme)
{
    $this->theme = $theme
}

Troubleshooting

Clear config after runing vendor publish (see Config section) to save issues related to config caching by running:

php artisan config:cache

php artisan config:clear

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-14