AboutUsController.php
3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
* 管理端控制层: 关于我们 控制类
+-----------------------------------------------------------------------------------------------------------------------
*
* PHP version 7
*
* @category App\Admin\Controllers
* @package App\Admin\Controllers
* @author Richer <yangzi1028@163.com>
* @date 2022年2月16日14:15:18
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
namespace App\Admin\Controllers;
use App\Admin\Rewrite\Form;
use App\Models\AboutUs;
use Encore\Admin\Form\Tools;
use Encore\Admin\Layout\Content;
use Symfony\Component\HttpFoundation\Response;
/**
* Class AboutUsController.
*
* @category App\Admin\Controllers
* @package App\Admin\Controllers
* @author Richer <yangzi1028@163.com>
* @date 2022年2月16日14:15:18
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
class AboutUsController extends BaseController
{
// 使用Grid和Form的trait
/**
* AboutUsController constructor.
*
* @param AboutUs $model 注入model
*/
public function __construct(AboutUs $model)
{
// 资源显示的中文名称
$this->title = $model::OBJ_NAME_ZH;
// 资源显示的名称
$this->type = $model::OBJ_NAME;
// 表名称
$this->table = $model::TABLE;
// 是否可查看
$this->can_view = true;
// 是否可新增
$this->can_create = true;
// 是否可编辑
$this->can_edit = true;
// 是否可删除
$this->can_delete = true;
// 是否开启下拉菜单
$this->dropdownActions = false;
// 执行父类构造方法
parent::__construct($model);
}
/**
* User setting page.
*
* @param Content $content
*
* @return Content
*/
public function getAboutUs(Content $content)
{
// 获取 boss
$boss = $this->model->first();
$form = $this->settingForm();
$form->tools(
function (Tools $tools) {
$tools->disableList();
$tools->disableDelete();
$tools->disableView();
}
);
if ($boss) {
return $content
->title(trans('admin.user_setting'))
->body($form->edit(optional($boss)->id));
} else {
return $content
->title(trans('admin.user_setting'))
->body($form);
}
}
/**
* Update user setting.
*
* @return Response
*/
public function postAboutUs()
{
return $this->settingForm()->store();
}
/**
* Update user setting.
*
* @return Response
*/
public function putAboutUs()
{
return $this->settingForm()->update(1);
}
/**
* Model-form for user setting.
*
* @return Form
*/
protected function settingForm()
{
$form = new Form($this->model);
$form->text('title', '标题')->required()->setWidth(10, 1)->setGroupClass('col-md-12');
$form->editor('body', '详情')->required()->help('请上传小于1G的视频...')->setWidth(10, 1)->setGroupClass('col-md-12');
// $this->formRichTextField('body', '详情', 1);
// $form->textarea('name', trans('admin.name'))->rules('required')->setWidth(10, 1)->setGroupClass('col-md-12');
$form->setAction(admin_url('about-us'));
$form->saved(function () {
admin_toastr(trans('admin.update_succeeded'));
return redirect(admin_url('about-us'));
});
return $form;
}
}