Skip to content

Commit 3f88699

Browse files
author
songzou
committed
bugfix
1 parent 7a8fa7f commit 3f88699

File tree

3 files changed

+23
-28
lines changed

3 files changed

+23
-28
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
laravel-admin-ext/config
22
========================
33

4-
[![StyleCI](https://styleci.io/repos/97664136/shield?branch=master)](https://styleci.io/repos/97664136)
54
[![Packagist](https://img.shields.io/packagist/l/laravel-admin-ext/config.svg?maxAge=2592000)](https://packagist.org/packages/laravel-admin-ext/config)
65
[![Total Downloads](https://img.shields.io/packagist/dt/laravel-admin-ext/config.svg?style=flat-square)](https://packagist.org/packages/laravel-admin-ext/config)
76

7+
Inspired by https://github.com/laravel-backpack/settings.
88

9+
## Screenshot
910

10-
Inspired by https://github.com/laravel-backpack/settings.
11+
![wx20170810-100226](https://user-images.githubusercontent.com/1479100/29151322-0879681a-7db3-11e7-8005-03310686c884.png)
1112

1213
## Installation
1314

@@ -17,7 +18,7 @@ $ composer require laravel-admin-ext/config
1718
$ php artisan migrate
1819
```
1920

20-
Open `app/Providers/AppServiceProvider.php`, and call the `Config::boot` method within the `boot` method:
21+
Open `app/Providers/AppServiceProvider.php`, and call the `Config::load()` method within the `boot` method:
2122

2223
```php
2324
<?php
@@ -31,12 +32,12 @@ class AppServiceProvider extends ServiceProvider
3132
{
3233
public function boot()
3334
{
34-
Config::boot();
35+
Config::load();
3536
}
3637
}
3738
```
3839

39-
then run:
40+
Then run:
4041

4142
```
4243
$ php artisan admin:import config

src/Config.php

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,21 @@
44

55
use Encore\Admin\Admin;
66
use Encore\Admin\Extension;
7-
use Illuminate\Support\Facades\Route;
87

98
class Config extends Extension
109
{
10+
/**
11+
* Load configure into laravel from database.
12+
*
13+
* @return void
14+
*/
15+
public static function load()
16+
{
17+
foreach (ConfigModel::all(['name', 'value']) as $config) {
18+
config([$config['name'] => $config['value']]);
19+
}
20+
}
21+
1122
/**
1223
* Bootstrap this package.
1324
*
@@ -17,8 +28,6 @@ public static function boot()
1728
{
1829
static::registerRoutes();
1930

20-
static::loadConfig();
21-
2231
Admin::extend('config', __CLASS__);
2332
}
2433

@@ -29,29 +38,12 @@ public static function boot()
2938
*/
3039
protected static function registerRoutes()
3140
{
32-
/* @var \Illuminate\Routing\Router $router */
33-
Route::group(['prefix' => config('admin.route.prefix')], function ($router) {
34-
35-
$attributes = array_merge([
36-
'middleware' => config('admin.route.middleware'),
37-
], static::config('route', []));
38-
39-
Route::group($attributes, function ($router) {
40-
41-
/* @var \Illuminate\Routing\Router $router */
42-
$router->resource('config', 'Encore\Admin\Config\ConfigController');
43-
});
44-
41+
parent::routes(function ($router) {
42+
/* @var \Illuminate\Routing\Router $router */
43+
$router->resource('config', 'Encore\Admin\Config\ConfigController');
4544
});
4645
}
4746

48-
protected static function loadConfig()
49-
{
50-
foreach (ConfigModel::all(['name', 'value']) as $config) {
51-
config([$config['name'] => $config['value']]);
52-
}
53-
}
54-
5547
/**
5648
* {@inheritdoc}
5749
*/

src/ConfigServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ public function boot()
1414
if ($this->app->runningInConsole()) {
1515
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
1616
}
17+
18+
Config::boot();
1719
}
1820
}

0 commit comments

Comments
 (0)