https://github.com/isaeken/laravel-theme-system
Theme system for Laravel Framework.
https://github.com/isaeken/laravel-theme-system
blade framework laravel php system theme
Last synced: 11 months ago
JSON representation
Theme system for Laravel Framework.
- Host: GitHub
- URL: https://github.com/isaeken/laravel-theme-system
- Owner: isaeken
- License: mit
- Created: 2020-07-19T15:41:19.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-07-14T06:55:37.000Z (over 3 years ago)
- Last Synced: 2024-05-01T15:28:24.046Z (almost 2 years ago)
- Topics: blade, framework, laravel, php, system, theme
- Language: PHP
- Homepage:
- Size: 54.7 KB
- Stars: 70
- Watchers: 2
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# Laravel Theme System

[](https://packagist.org/packages/isaeken/laravel-theme-system)

[](https://github.com/isaeken/laravel-theme-system/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
[](https://packagist.org/packages/isaeken/laravel-theme-system)
## Installation and setup
### Installation
You can install the package via composer:
```bash
composer require isaeken/laravel-theme-system
```
### Setup
You can publish the config file with:
```bash
php artisan vendor:publish --provider="IsaEken\ThemeSystem\ThemeSystemServiceProvider" --tag="theme-system-config" --tag="theme-system-migrations"
php artisan migrate
```
Run the following command in the terminal for initializing:
````shell
php artisan themes:init
````
## Usage
### Change the theme in runtime
````php
theme_system()->setTheme('your-theme-name');
````
### Get current theme name
````php
theme_system()->getCurrentTheme();
````
### Set theme per user
````php
// \App\Models\User.php
class User extends Authenticatable
{
use \IsaEken\ThemeSystem\Traits\CanChooseTheme; // Add this
// ...
}
````
````php
// 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.
````
### Creating theme
Run the following command in the terminal.
````shell
php artisan make:theme your-theme-name
````
Change theme in PHP or application config.
### Webpack
> Do not change the main ``webpack.mix.js`` file.
A special ``"webpack.mix.js"`` file is created for each theme.
The ``"webpack.mix.js"`` file of the default theme is in the ``"resources"`` folder.
You can continue to use the ``"webpack.mix.js"`` as normal in the default theme.
However, in themes you should use it as in the example.
````js
const mix = require('laravel-mix');
mix
.js(themeResourceRoot + '/js/app.js', 'js')
.postCss(themeResourceRoot + '/css/app.css', 'css', [
//
]);
exports.mix = mix;
````
### Middleware to set a theme
Register ``ThemeMiddleware`` in ``app\Http\Kernel.php``:
````php
protected $routeMiddleware = [
// ...
'theme' => \IsaEken\ThemeSystem\Http\Middlewares\ThemeMiddleware::class,
];
````
Example usages:
````php
Route::group(['middleware' => 'theme:your-theme-name'], function () {
// ...
});
Route::get('/hello-world', fn () => 'Hello World!')->middleware('theme:your-theme-name');
````
### If you need to advanced methods, see ThemeSystem class.
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
## Security Vulnerabilities
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
## Credits
- [Isa Eken](https://github.com/isaeken)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.