PHPackages                             petercoles/themes - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. petercoles/themes

ActiveLibrary

petercoles/themes
=================

Opinionated theme manager for Laravel

0.2.1(9y ago)488MITPHPPHP &gt;=5.6.0

Since Apr 20Pushed 9y ago2 watchersCompare

[ Source](https://github.com/petercoles/Themes)[ Packagist](https://packagist.org/packages/petercoles/themes)[ Docs](https://github.com/petercoles/themes)[ RSS](/packages/petercoles-themes/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (6)Versions (5)Used By (0)

Themes for Laravel
==================

[](#themes-for-laravel)

[![SensioLabsInsight](https://camo.githubusercontent.com/ee9424cd029fde70454bf636df9a0c02ce1b018f28c634ce3ed401d675c98ce9/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f38386263636234622d343038362d343439622d613839322d6631303631306535303235302f6d696e692e706e67)](https://insight.sensiolabs.com/projects/88bccb4b-4086-449b-a892-f10610e50250)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/6b333553d6265a6e4d03f69c47503d7c7fbf251e54b9ee82ab0f60cbae23a705/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7065746572636f6c65732f5468656d65732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/petercoles/Themes/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/bae560032e1c210346fc6269f0b79146a37a0a179876114529bfd3e949b4873d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7065746572636f6c65732f5468656d65732f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/petercoles/Themes/?branch=master)[![Build Status](https://camo.githubusercontent.com/604ddff8636016cc24495d0a91e31eabd7ce45f03b3875e04606c27b3a815789/68747470733a2f2f7472617669732d63692e6f72672f7065746572636f6c65732f5468656d65732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/petercoles/Themes)[![License](https://camo.githubusercontent.com/e498eead712d82d9ee1af0a4850acd2e46ea48c48fb9ce5a3d2ab64f28f95b34/687474703a2f2f696d672e736869656c64732e696f2f3a6c6963656e73652d6d69742d626c75652e737667)](http://doge.mit-license.org)

Introduction
------------

[](#introduction)

This is far from being the only theme management package available for Laravel (see below). Each has its own approach. This one's point of uniqueness is its no-coding approach. Instead you simply install it, set config rules and the package uses those rules to determine which theme to use.

Other Laravel Theme Packages that you might want to consider
------------------------------------------------------------

[](#other-laravel-theme-packages-that-you-might-want-to-consider)

- [teeplus/theme](https://packagist.org/packages/teepluss/theme)
- [igaster/laravel-theme](https://packagist.org/packages/igaster/laravel-theme)
- [karlomikus/theme](https://packagist.org/packages/karlomikus/theme)
- [buzz/laravel-theme](https://packagist.org/packages/buzz/laravel-theme)

Installation
------------

[](#installation)

At the command line run

```
composer require petercoles/themes

```

then add the service provider to the providers entry in your config/app.php file

```
    'providers' => [
        // ...
        PeterColes\Themes\ThemesServiceProvider::class,
        // ...
    ],

```

Configuration
-------------

[](#configuration)

Publish the configuration file from the command line with

```
php artisan vendor:publish

```

or if you only want to publish this package

```
php artisan vendor:publish --provider="PeterColes\Themes\ThemesServiceProvider"

```

The resulting themes config file has a single default setting that will leave your site untouched. To start controlling the themes used, see the next section ...

Creating Your Themes
--------------------

[](#creating-your-themes)

By default this package will continue to use your views and assets in their default Laravel locations. To start to over-ride these defaults with context-based alternatives, first create a theme folder at the same level as your Laravel's resource folder. Inside that create a folder for one or more themes.

For example:

```
.
|-- app
|-- ...
|-- resources
|-- storage
|-- themes
    |-- myFirstTheme
    |-- mySecondTheme
|--vendor

```

Within each theme place your config, asset and views files. For example:

```
.
|-- themes
    |-- myFirstTheme
        |-- config
        |-- resources
            |-- assets
                |-- img
                |-- js
                |-- sass
            |-- views

```

### Configs

[](#configs)

Config files will be detected and loaded automatically. They will *completely replace* any files with the same name in the normal config folder, rather than overriding individual settings.

### Assets

[](#assets)

There is no automatic management of assets. Elixir is recommended, but any similar build system can be used to process, prepare and place them in you site's public folder. To avoid collisions, it's recommended that you place them in subfolders with the same name as the theme's folder, for example:

```
.
|-- public
    |-- myFirstTheme
        |-- img
        |-- js
        |-- sass

```

If you do so, then the theme\_assets() and secure\_theme\_assets() helper functions are available for inserting links to the assets into view. For example the following will autodetect which theme is in use and point to the appropriate scripts file:

```
theme_assets('app.js') // will generate "http://www.example.com/theme-name/app.js"

```

### Views

[](#views)

Views are detected automatically. If your route, your controller or another view calls for a view that is present in your theme, that's the version that will be used, otherwise it will look for the view in the normal views hierarchy, and if it doesn't find it there either, the normal exception will be thrown. So if the current theme is "foo" then `view('pages.about')` will look first for `themes/foo/views/pages/about.blade.php` and if not found then for `resources/views/pages/about.blade.php`.

### ... one more thing

[](#-one-more-thing)

There's also a helper, `themes_path()` to build the file path to the themes folder and, like other path helpers in Laravel will prepend that path to any received as a string parameter.

Setting Rules for Theme Selection
---------------------------------

[](#setting-rules-for-theme-selection)

To control the selection of themes, you can rules to the themes config file. These rules follw the same syntax as Laravel's validation rules. The package will process each set of rules in turn and if a match is found will set the themes to the given value. For example the themes config:

```
