From f84feb7a4cf9711d7e4007d274727008d4856641 Mon Sep 17 00:00:00 2001 From: vagrant Date: Wed, 11 Apr 2018 04:57:16 +0000 Subject: [PATCH] Admin can manage site settings --- config/administrator.php | 3 + config/administrator/settings/site.php | 87 +++++++++++++++++++++++ resources/views/layouts/_footer.blade.php | 2 +- resources/views/layouts/app.blade.php | 5 +- storage/administrator_settings/site.json | 1 + 5 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 config/administrator/settings/site.php create mode 100644 storage/administrator_settings/site.json diff --git a/config/administrator.php b/config/administrator.php index f006074..ed23846 100644 --- a/config/administrator.php +++ b/config/administrator.php @@ -47,6 +47,9 @@ 'topics' , 'replies' , ] , + '站点管理' => [ + 'settings.site' , + ] , ] , /* diff --git a/config/administrator/settings/site.php b/config/administrator/settings/site.php new file mode 100644 index 0000000..8a3a77f --- /dev/null +++ b/config/administrator/settings/site.php @@ -0,0 +1,87 @@ + '站点设置' , + + // 访问权限判断 + 'permission' => function () { + // 只允许站长管理站点配置 + return Auth::user ()->hasRole ( 'Founder' ); + } , + + // 站点配置的表单 + 'edit_fields' => [ + 'site_name' => [ + // 表单标题 + 'title' => '站点名称' , + + // 表单条目类型 + 'type' => 'text' , + + // 字数限制 + 'limit' => 50 , + ] , + 'contact_email' => [ + 'title' => '联系人邮箱' , + 'type' => 'text' , + 'limit' => 50 , + ] , + 'seo_description' => [ + 'title' => 'SEO - Description' , + 'type' => 'textarea' , + 'limit' => 250 , + ] , + 'seo_keyword' => [ + 'title' => 'SEO - Keywords' , + 'type' => 'textarea' , + 'limit' => 250 , + ] , + ] , + + // 表单验证规则 + 'rules' => [ + 'site_name' => 'required|max:50' , + 'contact_email' => 'email' , + ] , + + 'messages' => [ + 'site_name.required' => '请填写站点名称。' , + 'contact_email.email' => '请填写正确的联系人邮箱格式。' , + ] , + + // 数据即将保持的触发的钩子,可以对用户提交的数据做修改 + 'before_save' => function ( &$data ) { + // 为网站名称加上后缀,加上判断是为了防止多次添加 + if ( strpos ( $data[ 'site_name' ] , 'Powered by LaraBBS' ) === false ) { + $data[ 'site_name' ] .= ' - Powered by LaraBBS'; + } + } , + + // 你可以自定义多个动作,每一个动作为设置页面底部的『其他操作』区块 + 'actions' => [ + + // 清空缓存 + 'clear_cache' => [ + 'title' => '更新系统缓存' , + + // 不同状态时页面的提醒 + 'messages' => [ + 'active' => '正在清空缓存...' , + 'success' => '缓存已清空!' , + 'error' => '清空缓存时出错!' , + ] , + + // 动作执行代码,注意你可以通过修改 $data 参数更改配置信息 + 'action' => function ( &$data ) { + \Artisan::call ( 'cache:clear' ); + return true; + } + ] , + ] , +]; \ No newline at end of file diff --git a/resources/views/layouts/_footer.blade.php b/resources/views/layouts/_footer.blade.php index ffb6c8b..a54af53 100644 --- a/resources/views/layouts/_footer.blade.php +++ b/resources/views/layouts/_footer.blade.php @@ -5,6 +5,6 @@ style="color: #e27575;font-size: 14px;">❤

-

联系我们

+

联系我们

\ No newline at end of file diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 10f794b..1f91aae 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -8,8 +8,9 @@ - @yield('title', 'LaraBBS') - Laravel 进阶教程 - + @yield('title', 'LaraBBS') - {{ setting('site_name', 'Laravel 进阶教程') }} + + diff --git a/storage/administrator_settings/site.json b/storage/administrator_settings/site.json new file mode 100644 index 0000000..8172cbf --- /dev/null +++ b/storage/administrator_settings/site.json @@ -0,0 +1 @@ +{"site_name":"laravel \u6559\u7a0b\u5b66\u4e60 - Powered by LaraBBS","contact_email":"785662290@qq.com","seo_description":"LaraBBS \u7231\u597d\u8005","seo_keyword":"LaraBBS \u5b66\u4e60"} \ No newline at end of file