isaeken / laravel-theme-system
Laravel 主题系统
v2.4
2021-10-11 13:20 UTC
Requires
- php: ^8.0
- illuminate/contracts: ^8.62
- spatie/laravel-package-tools: ^1.9
Requires (Dev)
- nunomaduro/collision: ^5.10
- orchestra/testbench: ^6.21
- orchestra/testbench-browser-kit: ^6.16
- pestphp/pest: ^1.20
- pestphp/pest-plugin-laravel: ^1.1
- spatie/laravel-ray: ^1.26
- vimeo/psalm: ^4.10
README
安装和配置
安装
您可以通过 Composer 安装此包
composer require isaeken/laravel-theme-system
配置
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="IsaEken\ThemeSystem\ThemeSystemServiceProvider" --tag="theme-system-config" --tag="theme-system-migrations" php artisan migrate
在终端运行以下命令进行初始化
php artisan themes:init
用法
运行时更改主题
theme_system()->setTheme('your-theme-name');
获取当前主题名称
theme_system()->getCurrentTheme();
为每个用户设置主题
// \App\Models\User.php class User extends Authenticatable { use \IsaEken\ThemeSystem\Traits\CanChooseTheme; // Add this // ... }
// In your controller or middleware auth()->user()->theme; // theme for user. auth()->user()->theme = 'default'; // theme is saved to db. auth()->user()->themeApply(); // changed current theme to user theme.
创建主题
在终端运行以下命令。
php artisan make:theme your-theme-name
在 PHP 或应用配置中更改主题
Webpack
不要更改主
webpack.mix.js文件。
为每个主题创建一个特殊的 "webpack.mix.js" 文件。
默认主题的 "webpack.mix.js" 文件位于 "resources" 文件夹中。
您可以在默认主题中继续正常使用 "webpack.mix.js"。
然而,在主题中,您应该像示例中那样使用。
const mix = require('laravel-mix'); mix .js(themeResourceRoot + '/js/app.js', 'js') .postCss(themeResourceRoot + '/css/app.css', 'css', [ // ]); exports.mix = mix;
用于设置主题的中间件
在 app\Http\Kernel.php 中注册 ThemeMiddleware
protected $routeMiddleware = [ // ... 'theme' => \IsaEken\ThemeSystem\Http\Middlewares\ThemeMiddleware::class, ];
示例用法
Route::group(['middleware' => 'theme:your-theme-name'], function () { // ... }); Route::get('/hello-world', fn () => 'Hello World!')->middleware('theme:your-theme-name');
如果您需要高级方法,请参阅 ThemeSystem 类。
变更日志
请参阅 变更日志 了解最近的变化。
贡献
请参阅 贡献指南 了解详细信息。
安全漏洞
请查看 我们的安全策略 了解如何报告安全漏洞。
致谢
许可协议
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。