Skip to content

Commit 23ef1c1

Browse files
committed
Update documentation in Readme
1 parent 46d7e57 commit 23ef1c1

File tree

1 file changed

+111
-5
lines changed

1 file changed

+111
-5
lines changed

README.md

+111-5
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,118 @@ This Laravel package adds multi-theme support to your application. It also provi
1111

1212
## Features
1313
- Any number of themes
14-
- Fallback theme support; It allows creating a child theme to extend any theme
15-
- Provides a simple authentication scaffolding similar to laravel/ui & laravel/breeze package
16-
- Provides frontend presets for bootstrap, tailwind, vue, and react
14+
- Fallback theme support (Wordpress style); It allows creating a child theme to extend any theme
15+
- Provides a simple authentication scaffolding similar to `laravel/ui` & `laravel/breeze` package
16+
- Provides frontend presets for `bootstrap`, `tailwind`, `vue`, and `react`
1717

18-
## Documentation
19-
To install, configure and learn how to use Laravel Themer package please go to the [Documentation](https://qirolab.com/posts/laravel-themer-multi-theme-support-for-laravel-application-1609688215).
18+
## Installation and setup
19+
20+
You can install this package via composer using:
21+
```bash
22+
composer require qirolab/laravel-themer
23+
```
24+
25+
Publish a configuration file:
26+
```bash
27+
php artisan vendor:publish --provider="Qirolab\Theme\ThemeServiceProvider" --tag="config"
28+
```
29+
30+
## Creating a theme
31+
32+
Run the following command in the terminal:
33+
```bash
34+
php artisan make:theme
35+
```
36+
<img
37+
src="https://i.imgur.com/qLy7Iex.png" alt="Create theme" />
38+
39+
This command will ask you to enter theme name, CSS framework, js framework, and optional auth scaffolding.
40+
41+
## Useful Theme methods:
42+
43+
```php
44+
// Set active theme
45+
Theme::set('theme-name');
46+
47+
// Get current active theme
48+
Theme::active();
49+
50+
// Get current parent theme
51+
Theme::parent();
52+
53+
// Clear theme. So, no theme will be active
54+
Theme::clear();
55+
56+
// Get theme path
57+
Theme::path($path = 'views');
58+
// output: app-root-path/themes/active-theme/views
59+
60+
Theme::path($path = 'views', $themeName = 'admin');
61+
// output: app-root-path/themes/admin/views
62+
```
63+
64+
## Middleware to set a theme
65+
Register `ThemeMiddleware` in `app\Http\Kernel.php`:
66+
67+
```php
68+
protected $routeMiddleware = [
69+
// ...
70+
'theme' => \Qirolab\Theme\Middleware\ThemeMiddleware::class,
71+
];
72+
```
73+
Examples for middleware usage:
74+
```php
75+
// Example 1: set theme for a route
76+
Route::get('/dashboard', 'DashboardController@index')
77+
->middleware('theme:dashboard-theme');
78+
79+
80+
// Example 2: set theme for a route-group
81+
Route::group(['middleware'=>'theme:admin-theme'], function() {
82+
// "admin-theme" will be applied to all routes defined here
83+
});
84+
85+
86+
// Example 3: set child and parent theme
87+
Route::get('/dashboard', 'DashboardController@index')
88+
->middleware('theme:child-theme,parent-theme');
89+
```
90+
91+
## Asset compilation
92+
To compile the theme assets, you need to add the theme's `webpack.mix.js` in
93+
the root `webpack.mix.js`.
94+
95+
```js
96+
// add this in the root `webpack.mix.js`
97+
require(`${__dirname}/themes/theme-name/webpack.mix.js`);
98+
```
99+
Now you can run the `npm install` and `npm run dev` command to compile theme assets.
100+
101+
You can also modify the root `webpack.mix.js` with the following code:
102+
```js
103+
let theme = process.env.npm_config_theme;
104+
105+
if(theme) {
106+
require(`${__dirname}/themes/${theme}/webpack.mix.js`);
107+
} else {
108+
// default theme to compile if theme is not specified
109+
require(`${__dirname}/themes/theme-name/webpack.mix.js`);
110+
}
111+
```
112+
113+
Now, to compile a particular theme run the following command:
114+
115+
```bash
116+
npm run dev --theme=theme-name
117+
118+
# or
119+
120+
npm run watch --theme=theme-name
121+
122+
# or
123+
124+
npm run production --theme=theme-name
125+
```
20126

21127
## Support us
22128
We invest a lot of resources into video tutorials and creating open-source packages. If you like what I do or if you ever made use of something I built or from my videos, consider supporting us. This will allow us to focus even more time on the tutorials and open-source projects we're working on.

0 commit comments

Comments
 (0)