├── README.md ├── composer.json └── src └── Tony ├── Themes ├── FileViewFinder.php ├── Theme.php ├── ThemeFacade.php ├── ThemeMiddleware.php └── ThemeServiceProvider.php └── composer.json /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Theme 2 | 3 | **The simpliest of theme switching for Laravel 5** 4 | 5 | - Installation 6 | - Usage 7 | 8 | 9 | ## Installation 10 | 11 | ### Laravel 5.1+ 12 | 13 | Install Laravel Theme manager: 14 | 15 | ``` json 16 | composer require codewithtony/larathemes 17 | ``` 18 | 19 | At `config/app.php`, add the Service Provider and the Facade: 20 | 21 | ```php 22 | 'providers' => [ 23 | Tony\Themes\ThemeServiceProvider::class, 24 | ] 25 | 26 | //... 27 | 28 | 'aliases' => [ 29 | 'Theme' => Tony\Themes\Themes\ThemeFacade::class, 30 | ] 31 | ``` 32 | 33 | ## Usage 34 | 35 | ### Recommended Structure 36 | 37 | ``` 38 | themes 39 | ├── [theme name] 40 | | └── assets 41 | | └── views 42 | | 43 | └── [theme name] 44 | └── assets 45 | └── views 46 | ``` 47 | 48 | ### Setting a theme 49 | 50 | Changing your theme is easy 51 | 52 | ```php 53 | Theme::set('my-theme') 54 | ``` 55 | 56 | Easily use the Middleware to change themes for an entire group 57 | 58 | ```php 59 | Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'theme:admin'], function () { 60 | //... 61 | }); 62 | ``` 63 | 64 | ### Calling a view 65 | 66 | Load your views like normal, Laravel Theme will look for your view in the set theme and if it isn't found, view finding will remain the same 67 | 68 | You can reuse views by storing them outside of your theme and just uses view('layout.master') and have your layout/master.blade.php inside you themes. 69 | 70 | ### Assets 71 | 72 | Your assets will need to be sent to your public folder still. 73 | 74 | ## Contribute 75 | 76 | Your help is more than welcome! 77 | 78 | ## License 79 | 80 | Licensed under the [The MIT License (MIT)](http://opensource.org/licenses/MIT). Please see [LICENSE](LICENSE) for more information. 81 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "codewithtony/larathemes", 3 | "description": "Theme Manager for Laravel 5", 4 | "keywords": [ "Laravel 5", "Themes", "Laravel Theme", "Theme Manager" ], 5 | "homepage": "https://github.com/codewithtony/larathemes", 6 | "type": "library", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Tony.", 11 | "email": "tony@codewithtony.com", 12 | "homepage": "http://www.codewithtony.com" 13 | } 14 | ], 15 | "support": { 16 | "issues": "https://github.com/codewithtony/larathemes/issues" 17 | }, 18 | "require": { 19 | "php": ">=5.4.0", 20 | "laravel/framework": "5.*" 21 | }, 22 | "autoload": { 23 | "psr-4": { 24 | "Tony\\Themes\\": "src/Tony/Themes/" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/Tony/Themes/FileViewFinder.php: -------------------------------------------------------------------------------- 1 | paths, $location); 18 | } 19 | 20 | /** 21 | * Allows us to remove view paths 22 | * 23 | * @param $location 24 | * @return void 25 | */ 26 | public function removeLocation($location) 27 | { 28 | //find and remove location if set 29 | if(($key = array_search($location, $this->paths)) == false) { 30 | unset($this->paths[$key]); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/Tony/Themes/Theme.php: -------------------------------------------------------------------------------- 1 | removeLocation(self::$theme . '/views'); 20 | //set theme and add location to view file finder 21 | if (is_dir($absolute_path)) self::$theme = $absolute_path; 22 | app('view.finder')->addLocation($absolute_path . '/views'); 23 | } 24 | } -------------------------------------------------------------------------------- /src/Tony/Themes/ThemeFacade.php: -------------------------------------------------------------------------------- 1 | aliasMiddleware('theme', ThemeMiddleware::class); 13 | } 14 | 15 | /** 16 | * Register the service provider. 17 | * 18 | * @return void 19 | */ 20 | public function register() 21 | { 22 | $this->app->singleton('view.finder', function($app) { 23 | $paths = $app['config']['view.paths']; 24 | return new FileViewFinder($app['files'], $paths); 25 | }); 26 | View::setFinder(app('view.finder')); 27 | 28 | $this->app->singleton('theme', function($app) { 29 | return new Theme(); 30 | }); 31 | } 32 | } -------------------------------------------------------------------------------- /src/Tony/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "codewithtony/larathemes", 3 | "description": "Theme Manager for Laravel 5", 4 | "keywords": [ "Laravel 5", "Themes", "Laravel Theme", "Theme Manager" ], 5 | "homepage": "https://github.com/codewithtony/larathemes", 6 | "type": "library", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Tony.", 11 | "email": "tony@codewithtony.com", 12 | "homepage": "http://www.codewithtony.com" 13 | } 14 | ], 15 | "support": { 16 | "issues": "https://github.com/codewithtony/larathemes/issues" 17 | }, 18 | "require": { 19 | "php": ">=5.4.0", 20 | "laravel/framework": "5.*" 21 | }, 22 | "autoload": { 23 | "psr-4": { 24 | "Tony\\Themes\\": "src/Tony/Themes/" 25 | } 26 | } 27 | } --------------------------------------------------------------------------------