浏览代码

fix init conflict with laravl frame

Vien 5 年之前
父节点
当前提交
dcaeb144a6
共有 3 个文件被更改,包括 93 次插入89 次删除
  1. 4 4
      .env.example
  2. 3 3
      README.md
  3. 86 82
      app/Providers/InitServiceProvider.php

+ 4 - 4
.env.example

@@ -7,11 +7,11 @@ APP_URL=http://localhost
 LOG_CHANNEL=stack
 
 DB_CONNECTION=mysql
-DB_HOST=127.0.0.1
+DB_HOST=localhost
 DB_PORT=3306
-DB_DATABASE=homestead
-DB_USERNAME=homestead
-DB_PASSWORD=secret
+DB_DATABASE=vienblog
+DB_USERNAME=root
+DB_PASSWORD=
 
 BROADCAST_DRIVER=log
 CACHE_DRIVER=file

+ 3 - 3
README.md

@@ -54,7 +54,7 @@ Markdown编辑器:支持拖拽粘贴上传图片、预览、全屏、分屏预
 ##### 获取源码
 
 ```
-git clone git@github.com:luvvien/laravel-blog.git
+git clone https://github.com/luvvien/laravel-blog.git
 ```
 
 ##### 进入项目目录后,用`composer`安装依赖
@@ -83,11 +83,11 @@ php artisan key:generate
 [...]
 
 DB_CONNECTION=mysql
-DB_HOST=127.0.0.1
+DB_HOST=localhost
 DB_PORT=3306
 DB_DATABASE=vienblog
 DB_USERNAME=root
-DB_PASSWORD=root
+DB_PASSWORD=
 
 [...]
 ```

+ 86 - 82
app/Providers/InitServiceProvider.php

@@ -25,97 +25,101 @@ class InitServiceProvider extends ServiceProvider
      */
     public function boot()
     {
-        //
-        $information = Information::query()
-            ->select('site_title', 'site_keywords', 'site_description', 'author_name', 'author_intro', 'author_avatar', 'navigation')
-            ->first();
-
+        try {
+            //
+            $information = Information::query()
+                ->select('site_title', 'site_keywords', 'site_description', 'author_name', 'author_intro', 'author_avatar', 'navigation')
+                ->first();
 
-        if ($information) {
-            $blog = [
-                "name" => $information->site_title,
-                "keywords" => $information->site_keywords,
-                "description" => $information->site_description,
-            ];
 
-            $this->app->get('config')->set('vienblog.blog', $blog);
+            if ($information) {
+                $blog = [
+                    "name" => $information->site_title,
+                    "keywords" => $information->site_keywords,
+                    "description" => $information->site_description,
+                ];
 
-            $author = [ // 博主
-                "name" => $information->author_name,
-                "description" => $information->author_intro,
-                "avatar" => $information->author_avatar,
-            ];
-
-            $this->app->get('config')->set('vienblog.author', $author);
-        }
+                $this->app->get('config')->set('vienblog.blog', $blog);
 
-        $switches = Switches::query()
-            ->select('name', 'status', 'extra')
-            ->get()->all();
+                $author = [ // 博主
+                    "name" => $information->author_name,
+                    "description" => $information->author_intro,
+                    "avatar" => $information->author_avatar,
+                ];
 
-        if ($switches) {
-            $dict = array();
-
-            foreach ($switches as $switch) {
-                $extra = json_decode($switch['extra'], true);
-                $dict[$switch['name']] = array('status' => intval($switch['status']) == 1,
-                    'extra' => is_null($extra) ? [] : $extra);
+                $this->app->get('config')->set('vienblog.author', $author);
             }
 
-            $sidebar = [
-                "carousel" => [
-                    "open" => $dict['carousel']['status'], // 是(true)否(false)开启 默认true 开启务必设置banners
-                    "banners" => $dict['carousel']['extra']
-                ],
-                "motto" => [ // 座右铭
-                    "open" => $dict['motto']['status'], // 是(true)否(false)开启 默认true,
-                    "title" => $dict['motto']['extra']['title'], // 标题
-                    "content" => $dict['motto']['extra']['content'] // 内容
-                ],
-                "tag" => [ // 标签
-                    "open" => $dict['tag']['status'], // 是(true)否(false)开启 默认true,
-                    "title" => $dict['tag']['extra']['title'], // 标题
-                    "count" => intval($dict['tag']['extra']['count']), // 展示数量
-                ],
-                "category" => [ // 分类
-                    "open" => $dict['category']['status'], // 是(true)否(false)开启 默认true,
-                    "title" => $dict['category']['extra']['title'], // 标题
-                    "count" => intval($dict['category']['extra']['count']), // 展示数量
-                ],
-                "hot" => [ // 最热文章
-                    "open" => $dict['hot']['status'], // 是(true)否(false)开启 默认true,
-                    "title" => $dict['hot']['extra']['title'], // 标题
-                    "count" => intval($dict['hot']['extra']['count']), // 展示数量
-                ],
-                "latest" => [ // 最新文章
-                    "open" => $dict['latest']['status'], // 是(true)否(false)开启 默认true,
-                    "title" => $dict['latest']['extra']['title'], // 标题
-                    "count" => intval($dict['latest']['extra']['count']), // 展示数量
-                ],
-                "popular" => [ // 刚有人看的文章
-                    "open" => $dict['popular']['status'], // 是(true)否(false)开启 默认true,
-                    "title" => $dict['popular']['extra']['title'], // 标题
-                    "count" => intval($dict['popular']['extra']['count']), // 展示数量
-                ],
-            ];
-
-            $adsense_script = $dict['adsense']['extra'];
-            $adsense = [
-                "open" => $dict['adsense']['status'], // Google AdSense Auto AD 开关 默认关闭 开启需要在后台中添加 AdSense代码
-                "script" => array_key_exists('script', $adsense_script) ? $adsense_script['script'] : ""
-            ];
-            $counter_script = $dict['counter']['extra'];
-            $counter = [
-                "open" => $dict['counter']['status'], // 统计工具(例如百度统计、StatCounter等) 开关 默认关闭 开启需要在后台中添加相关代码
-                "script" => array_key_exists('script', $counter_script) ? $counter_script['script'] : ""
-            ];
-
-            $this->app->get('config')->set('vienblog.sidebar', $sidebar);
-            $this->app->get('config')->set('vienblog.ad', $adsense);
-            $this->app->get('config')->set('vienblog.counter', $counter);
-            $this->app->get('config')->set('vienblog.baidu.auto_push', $dict['baidu_autopush']['status']);
+            $switches = Switches::query()
+                ->select('name', 'status', 'extra')
+                ->get()->all();
+
+            if ($switches) {
+                $dict = array();
+
+                foreach ($switches as $switch) {
+                    $extra = json_decode($switch['extra'], true);
+                    $dict[$switch['name']] = array('status' => intval($switch['status']) == 1,
+                        'extra' => is_null($extra) ? [] : $extra);
+                }
+
+                $sidebar = [
+                    "carousel" => [
+                        "open" => $dict['carousel']['status'], // 是(true)否(false)开启 默认true 开启务必设置banners
+                        "banners" => $dict['carousel']['extra']
+                    ],
+                    "motto" => [ // 座右铭
+                        "open" => $dict['motto']['status'], // 是(true)否(false)开启 默认true,
+                        "title" => $dict['motto']['extra']['title'], // 标题
+                        "content" => $dict['motto']['extra']['content'] // 内容
+                    ],
+                    "tag" => [ // 标签
+                        "open" => $dict['tag']['status'], // 是(true)否(false)开启 默认true,
+                        "title" => $dict['tag']['extra']['title'], // 标题
+                        "count" => intval($dict['tag']['extra']['count']), // 展示数量
+                    ],
+                    "category" => [ // 分类
+                        "open" => $dict['category']['status'], // 是(true)否(false)开启 默认true,
+                        "title" => $dict['category']['extra']['title'], // 标题
+                        "count" => intval($dict['category']['extra']['count']), // 展示数量
+                    ],
+                    "hot" => [ // 最热文章
+                        "open" => $dict['hot']['status'], // 是(true)否(false)开启 默认true,
+                        "title" => $dict['hot']['extra']['title'], // 标题
+                        "count" => intval($dict['hot']['extra']['count']), // 展示数量
+                    ],
+                    "latest" => [ // 最新文章
+                        "open" => $dict['latest']['status'], // 是(true)否(false)开启 默认true,
+                        "title" => $dict['latest']['extra']['title'], // 标题
+                        "count" => intval($dict['latest']['extra']['count']), // 展示数量
+                    ],
+                    "popular" => [ // 刚有人看的文章
+                        "open" => $dict['popular']['status'], // 是(true)否(false)开启 默认true,
+                        "title" => $dict['popular']['extra']['title'], // 标题
+                        "count" => intval($dict['popular']['extra']['count']), // 展示数量
+                    ],
+                ];
+
+                $adsense_script = $dict['adsense']['extra'];
+                $adsense = [
+                    "open" => $dict['adsense']['status'], // Google AdSense Auto AD 开关 默认关闭 开启需要在后台中添加 AdSense代码
+                    "script" => array_key_exists('script', $adsense_script) ? $adsense_script['script'] : ""
+                ];
+                $counter_script = $dict['counter']['extra'];
+                $counter = [
+                    "open" => $dict['counter']['status'], // 统计工具(例如百度统计、StatCounter等) 开关 默认关闭 开启需要在后台中添加相关代码
+                    "script" => array_key_exists('script', $counter_script) ? $counter_script['script'] : ""
+                ];
+
+                $this->app->get('config')->set('vienblog.sidebar', $sidebar);
+                $this->app->get('config')->set('vienblog.ad', $adsense);
+                $this->app->get('config')->set('vienblog.counter', $counter);
+                $this->app->get('config')->set('vienblog.baidu.auto_push', $dict['baidu_autopush']['status']);
 
 //            dump($this->app->get('config')->get('vienblog'));
+            }
+        } catch (\Exception $e) {
+
         }
 
     }