Dcat-admin自定義站點配置頁面

阿珂發表於2021-04-26
用到的相關知識

dcat工具表單,dcat自定義函式admin_setting等

建立工具表單 (工具表單具體用法參照 dcat官方文件)
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'),
]);
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章