qirolab / laravel-themer
一个Laravel主题管理器,可以帮助您在Laravel项目中组织和维护主题。
Requires
- php: >=7.1.0
- facade/ignition-contracts: ^1.0
- illuminate/support: ^9.19|^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^7.0|^8.0|^9.0
- phpunit/phpunit: ^8.3|^9.0|^10.5
- vimeo/psalm: ^4.0|^5.22
README
此Laravel包为您应用程序添加了多主题支持。它还提供了一个简单的认证脚手架,作为构建Laravel应用程序的起点。它还预设了 Bootstrap
、Tailwind
、Vue
和 React
。因此,我认为它是 laravel/ui
和 laravel/breeze
包的不错替代品。
功能
- 任意数量的主题
- 回退主题支持(WordPress风格);允许创建子主题以扩展任何主题
- 提供类似于
laravel/ui
和laravel/breeze
的认证脚手架 - 导出所有认证控制器、测试和其他类似于
laravel/breeze
的文件 - 提供针对
Bootstrap
、Tailwind
、Vue 2
、Vue 3
和React
的前端预设
如果您不希望使用本包的认证脚手架,而是希望使用Laravel Fortify,也没有问题。您可以使用Laravel Themer与Fortify一起使用。Laravel Fortify只提供后端实现认证,不提供视图或前端预设。因此,使用Fortify进行后端认证,使用Laravel Themer进行视图和预设。
教程
以下是 Laravel Themer教程 的视频。
安装和设置
注意
Laravel Themer v2.x及更高版本支持 Vite。如果您想使用 Laravel Mix,则请尝试 Laravel Themer v1.7.1
您可以通过composer使用以下命令安装此包
composer require qirolab/laravel-themer
发布配置文件
php artisan vendor:publish --provider="Qirolab\Theme\ThemeServiceProvider" --tag="config"
创建主题
在终端中运行以下命令
php artisan make:theme
此命令将提示您输入主题名称、CSS框架、js框架和可选的认证脚手架。
有用的主题方法
// Set active theme Theme::set('theme-name'); // Get current active theme Theme::active(); // Get current parent theme Theme::parent(); // Clear theme. So, no theme will be active Theme::clear(); // Get theme path Theme::path($path = 'views'); // output: // /app-root-path/themes/active-theme/views Theme::path($path = 'views', $themeName = 'admin'); // output: // /app-root-path/themes/admin/views Theme::getViewPaths(); // Output: // [ // '/app-root-path/themes/admin/views', // '/app-root-path/resources/views' // ]
中间件设置主题
在 app\Http\Kernel.php
中注册 ThemeMiddleware
protected $routeMiddleware = [ // ... 'theme' => \Qirolab\Theme\Middleware\ThemeMiddleware::class, ];
中间件使用示例
// Example 1: set theme for a route Route::get('/dashboard', 'DashboardController@index') ->middleware('theme:dashboard-theme'); // Example 2: set theme for a route-group Route::group(['middleware'=>'theme:admin-theme'], function() { // "admin-theme" will be applied to all routes defined here }); // Example 3: set child and parent theme Route::get('/dashboard', 'DashboardController@index') ->middleware('theme:child-theme,parent-theme');
资产编译
要编译主题资产,首先需要在 package.json
文件的 scripts
部分中添加以下行。
"scripts": {
...
"dev:theme-name": "vite --config themes/theme-name/vite.config.js",
"build:theme-name": "vite build --config themes/theme-name/vite.config.js"
}
现在,要编译特定的主题,请运行以下命令
npm run dev:theme-name
# or
npm run build:theme-name
测试
composer test
支持我们
我们投入了大量资源进行视频教程和开源包的开发。如果您喜欢我所做的事情,或者您曾经使用过我构建的某些东西,或者从我的视频中受益,请考虑支持我们。这将使我们能够将更多时间投入到我们正在进行的教程和开源项目中。
非常感谢您的帮助! 🥰
更新日志
请参阅 更新日志 了解最近更改的更多信息。
贡献
请参阅 贡献指南 了解详细信息。
安全漏洞
请参阅 我们的安全策略 了解如何报告安全漏洞。
致谢
身份验证框架原型和预设来自 laravel/ui,laravel/breeze 和 laravel-frontend-presets/tailwindcss。
许可证
MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件。