Laravel Theme package allows you to convert your resources/views/ to independent theme.

Laravel Theme allows you to easily add multiple themes to your Laravel application. It provides the ability to create themes. It also offers a theme helper commands to allow for easy switch between themes, list available themes and more...

Laravel Theme is a great way to quickly add theme support to your Laravel application, allowing you to customize the look and feel of your app.

Installation

$ composer require vpominchuk/laravel-theme
$ php artisan vendor:publish --tag=theme-config

Converting your views to a theme

As long as your views located in resources/views/ you can convert them to a theme, just run:

$ php artisan theme:create

and answer some general question.

Available artisan commands

To get list of available artisan commands try:

$ php artisan theme list
Command Description
theme:list Show available themes
theme:info {theme_name} Get theme information
theme:create Create a new theme
theme:activate {theme_name} Activate theme

Switching between themes

You can easily switch between your themes in two different ways:

  1. Using artisan command
$ php artisan theme:activate {theme_name}
  1. Programmatically
use VPominchuk\LaravelThemeSupport\Contracts\ThemeManager;

/** @var ThemeManager $themeManager */
$themeManager = app(ThemeManager::class);
$themeManager->setActiveTheme($systemName); 

Customizing ThemeManager

By default, ThemeManager class stores information about active theme in framework/theme.json file.

{
    "active_theme": "default"
}

In real application you might want to use your own mechanism to store information about active theme.

To do it, you can create a new class, for instance:

namespace App\Services\Theme;


use App\Facades\Settings;
use VPominchuk\LaravelThemeSupport\Contracts\ThemeManager as ThemeManagerInterface;
use VPominchuk\LaravelThemeSupport\ThemeService;

class ThemeManager implements ThemeManagerInterface
{
    public function __construct(private ThemeService $themeService)
    { }

    public function getActiveTheme(): ?string
    {
        return Settings::get('ACTIVE_THEME');
    }

    public function setActiveTheme(string $systemName): bool
    {
        Settings::set('ACTIVE_THEME', $systemName);

        return $this->themeService->createPublicSymlink($systemName);
    }
}

Where Settings class is your Facade/Service/Model... which saves settings for your application. Replace it with your own class/method.

Now, open your AppServiceProvider.php and add following line to public function register() method:

$this->app->bind(
	VPominchuk\LaravelThemeSupport\Contracts\ThemeManager::class, 
	App\ThemeManager::class
);

Project GitHub: https://github.com/vpominchuk/laravel-theme