felixfrey/laravel-theme
Composer 安装命令:
composer require felixfrey/laravel-theme
包简介
Theme support for Laravel with assets, theme extends etc.
README 文档
README
Inspired by bigecko/laravel-theme. Fork of yaap/theme. Themes are stored inside default laravel's resources folder
Introduction
This package provides a simple way to manage themes in Laravel applications.
For example, you can develop multiple themes for your application and easily switch between themes for different purposes.
Requirements
This version requires PHP 8.1 and supports Laravel 10 - 13.
This package also provides support for Laravel Mix and Vite configurations.
| Package Version | Laravel 10 | Laravel 11 | Laravel 12 | Laravel 13 |
|---|---|---|---|---|
| 1 | ✅ | ✅ | ✅ | ✅ |
Installation
To get the latest version, simply require the project using Composer:
composer require "felixfrey/laravel-theme:^1.0.0"
or manually add line to composer.json
{
"require": {
"felixfrey/laravel-theme": "^1.0.0"
}
}
Optionally, publish config using artisan CLI (if you want to overwrite default config).
php artisan vendor:publish --provider="FelixFrey\LaravelTheme\ThemeServiceProvider"
Configuration
Package config
Config in config/theme.php file.
return [ /* |-------------------------------------------------------------------------- | Path to directory with themes |-------------------------------------------------------------------------- | | The directory with your themes. | */ 'path' => base_path('themes'), /* |-------------------------------------------------------------------------- | Path to directory with assets build |-------------------------------------------------------------------------- | | The directory with assets build in public directory. | */ 'assets_path' => 'themes', /* |-------------------------------------------------------------------------- | A pieces of theme collections |-------------------------------------------------------------------------- | | Inside a theme path we need to set up directories to | keep "layouts", "assets" and "partials". | */ 'containerDir' => [ 'assets' => 'assets', 'lang' => 'lang', 'layout' => 'views/layouts', 'partial' => 'views/partials', 'view' => 'views', ], ];
Theme config
Config in theme folder. Placeholder %theme_name% will be replaced with theme name on creation.
return [ /* |-------------------------------------------------------------------------- | Theme name |-------------------------------------------------------------------------- | | Use in assets publishing etc. | */ 'name' => '%theme_name%', /* |-------------------------------------------------------------------------- | Inherit from another theme |-------------------------------------------------------------------------- | | Set up inherit from another if the file is not exists. | */ 'inherit' => null, ];
Usage
Create theme with artisan CLI
Create command
The first time you have to create theme default structure, using the artisan command:
php artisan theme:create default
By default, it will use vite as assets builder. If you want to use laravel mix instead, use the command:
or with laravel mix:
php artisan theme:create default mix
Destroy command
To delete an existing theme, use the command:
php artisan theme:destroy default
Structure
Here is an example of the folder structure of project with theme
project-root
├── app/
<...>
├── public/
| ├── index.php
| └── themes/
| └── default/
| ├── js/
| | └── app.js
| ├── css/
| | └── styles.css
| └── images/
| └── icon.png
├── resources/
<...>
├── themes/
| ├── default/
| | ├── assets/
| | ├── lang/
| | ├── views/
| | | ├── layouts/
| | | ├── partials/
| | | └── hello.blade.php
| | └── config.php
| ├── admin/
| ├── views/
| ├── emails/
| | └── notify.blade.php
| └── hello.blade.php
Init theme
To init and use theme in your application, add the following code to any boot method in application service provider (e.g. AppServiceProvider):
use FelixFrey\LaravelTheme\Facades\ThemeLoader; class AppServiceProvider extends ServiceProvider { public function boot() { ThemeLoader::init('default'); } }
This will add to views find path:
themes/{$name}/views
Lang files will be added as well:
themes/{$name}/lang
Making view
View::make('hello'); View::make('emails.notify'); // or view('hello'); view('emails.notify');
Assets
Vite
If you use Vite, ensure vite.config.js have specified the input path for theme
import {defineConfig} from 'vite'; import laravel from 'laravel-vite-plugin'; export default defineConfig({ plugins: [ laravel({ input: [ 'themes/default/assets/js/app.js', // for default theme // ... ], refresh: true, }), ], });
Because app.js includes app.scss you can use the following code to include assets in your views:
<head> <!--...--> @vite([ 'themes/default/assets/js/app.js', ]) </head>
Laravel Mix
If you use Laravel Mix, ensure webpack.mix.js have specified mix configuration for theme
const mix = require('laravel-mix'); mix.disableNotifications(); mix.browserSync({ open: true, proxy: 'localhost:8000', files: [ 'app/**/*', 'routes/**/*', 'themes/**/*', // manually add this line ] }); // other configutraions... // mix for default theme mix.copyDirectory('themes/default/assets/img', 'public/themes/default/img'); mix.copyDirectory('themes/default/assets/fonts', 'public/themes/default/fonts'); // js mix.js(['themes/default/assets/js/app.js'], 'public/themes/default/js/app.min.js') // sass mix.sass('themes/default/assets/sass/app.scss', 'public/themes/default/css/app.min.css')
Then you can use the following code to include assets in your views:
in the <head> tag
<head> <!--...--> <link rel="stylesheet" href="{{ mix('/themes/default/css/app.min.css') }}"/> </head>
and before </body> tag
<body> <!--...--> <script type="text/javascript" src="{{ mix('/themes/default/js/app.min.js') }}"></script> </body>
To use images, you can use the following code:
<img src="{{ mix('themes/default/img/icon.png') }}" alt="icon">
Building layouts
Layouts using Components
Layouts using template inheritance
To build layouts we use template inheritance.
You can use @extends directive to specify a parent layout.
@extends('layouts.master') @include('partials.header') @section('content') <section id="main"> <h1>HOME</h1> </section> @stop @include('partials.footer')
Fallback capability
You still able to use default View::make('emails.notify') which is stored outside the themes directory.
License
MIT license.
felixfrey/laravel-theme 适用场景与选型建议
felixfrey/laravel-theme 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.29k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「asset」 「theme」 「layout」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 felixfrey/laravel-theme 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 felixfrey/laravel-theme 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 felixfrey/laravel-theme 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Asset for Bulma Free for YiiFramework v.3.0.
Listener to change layout for different module
A Bootstrap 4.x base theme for SilverStripe
Flexible Content & Repeater Fields for Laravel Nova.
Lucency Theme
Cells are view components for Laravel 4. They are mini-controllers with their own MVC stack, can invoke logic and render views.
统计信息
- 总下载量: 1.29k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-30