diff --git a/app/AdminAgent/Controllers/NoticeController.php b/app/AdminAgent/Controllers/NoticeController.php index 080f5c7..7b1a47c 100644 --- a/app/AdminAgent/Controllers/NoticeController.php +++ b/app/AdminAgent/Controllers/NoticeController.php @@ -25,6 +25,7 @@ class NoticeController extends AdminController $grid->column('id')->sortable(); $grid->column('author'); $grid->column('title'); + $grid->column('status','是否启用')->switch(); $grid->column('sort')->editable()->width(120); $grid->column('created_at'); $grid->column('updated_at'); @@ -57,6 +58,7 @@ class NoticeController extends AdminController $show->field('author'); $show->field('title'); $show->field('content')->unescape(); + $show->field('status','是否启用'); $show->field('sort'); $show->field('created_at'); $show->field('updated_at'); @@ -80,6 +82,7 @@ class NoticeController extends AdminController $form->text('author')->default(Admin::user()->name); $form->text('title')->required(); $form->editor('content'); + $form->switch('status','是否启用'); $form->text('sort')->default(255); })->saving(function (Form $form) { //不允许修改非自己的数据 diff --git a/app/Http/Controllers/Api/IndexController.php b/app/Http/Controllers/Api/IndexController.php index 844d7bb..32f1f1d 100644 --- a/app/Http/Controllers/Api/IndexController.php +++ b/app/Http/Controllers/Api/IndexController.php @@ -32,7 +32,7 @@ class IndexController extends Controller } # 公告 - $notice = Notice::where('agent_id', $this->agent_id)->limit(10) + $notice = Notice::where('agent_id', $this->agent_id)->status()->limit(10) ->orderBy('sort')->orderBy('id', 'desc')->get(['id', 'title']); # 我的频道 diff --git a/app/Http/Controllers/Api/NoticeController.php b/app/Http/Controllers/Api/NoticeController.php index 28bfd75..59cb8bf 100644 --- a/app/Http/Controllers/Api/NoticeController.php +++ b/app/Http/Controllers/Api/NoticeController.php @@ -15,6 +15,7 @@ class NoticeController extends Controller public function index() { $list = Notice::query()->where('agent_id', $this->agent_id) + ->status() ->select(['title', 'updated_at']) ->orderBy('id', 'DESC') ->simplePaginate(15); @@ -25,7 +26,7 @@ class NoticeController extends Controller { $id = (int)request()->input('id'); - $data = Notice::where('agent_id', $this->agent_id)->find($id); + $data = Notice::where('agent_id', $this->agent_id)->status()->find($id); if (!$data) { return $this->error('公告不存在或已删除'); } diff --git a/app/Models/Notice.php b/app/Models/Notice.php index 73a66c4..1a58e9b 100644 --- a/app/Models/Notice.php +++ b/app/Models/Notice.php @@ -7,4 +7,9 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; class Notice extends BaseModel { use HasFactory; + + public function scopeStatus($query) + { + return $query->where('status',1); + } } diff --git a/database/migrations/2021_09_18_153814_update_notice_table_table.php b/database/migrations/2021_09_18_153814_update_notice_table_table.php new file mode 100644 index 0000000..7a6368f --- /dev/null +++ b/database/migrations/2021_09_18_153814_update_notice_table_table.php @@ -0,0 +1,32 @@ +tinyInteger('status') + ->default(0) + ->comment('是否启用 0禁用 1启用'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +}