Dcat-admin自定义站点配置页面

Laravel框架
463
0
0
2022-04-10
标签   Dcat Admin
用到的相关知识
dcat工具表单,dcat自定义函数admin_setting等
创建工具表单
PHP artisan admin:form setting //创建工具表单 命令
在 form 方法中构建表单项,使用方法和数据表单一致
          $this->confirm(trans('hint.setting1'), trans('hint.setting2'));

        $this->text('web_name')->default(admin_setting('web_name', '网站名'));

        $this->text('company_name')->default(admin_setting('company_name', '公司名'));

        $this->text('url')->default(admin_setting('url', ''));

        $this->image('logo')->accept('jpg,png,gif,jpeg')->maxSize(1024)->required()->help(trans('hint.size') . trans('hint.no') . '1M')->autoUpload();

        $this->image('login_img')->accept('jpg,png,gif,jpeg')->maxSize(1024)->required()->help(trans('hint.size') . trans('hint.no') . '1M')->autoUpload();

        $this->text('web_inscribe');
在handle中写入如下代码
        admin_setting($input);
        return $this
            ->response()
            ->success(trans('hint.success'))
            ->refresh();
表单调用
     return $content
            ->header(trans('hint.systems'))
            ->body(new Card(new Setting()));
重写站点配置(在bootstrap.php初始化文件中)
if (file_exists('upload/' . admin_setting('logo'))) {
    $logo = '<img src="/upload/' . admin_setting('logo') . '" width="35">&nbsp;' . admin_setting('company_name');
    $mini = '<img src="/upload/' . admin_setting('logo') . '" >';
} else {
    $logo = config('admin.logo');
    $mini = config('admin.logo-mini');
}

config([
    'admin.title' => admin_setting('web_name'),
    'admin.name' => admin_setting('company_name'),
    'admin.logo' => $logo,
    'admin.logo-mini' => $mini,
    'app.url' => admin_setting('url'),
]);