Browse Source

公告启用

master
lemon 4 years ago
parent
commit
ab4653001f
  1. 3
      app/AdminAgent/Controllers/NoticeController.php
  2. 2
      app/Http/Controllers/Api/IndexController.php
  3. 3
      app/Http/Controllers/Api/NoticeController.php
  4. 5
      app/Models/Notice.php
  5. 32
      database/migrations/2021_09_18_153814_update_notice_table_table.php

3
app/AdminAgent/Controllers/NoticeController.php

@ -25,6 +25,7 @@ class NoticeController extends AdminController
$grid->column('id')->sortable(); $grid->column('id')->sortable();
$grid->column('author'); $grid->column('author');
$grid->column('title'); $grid->column('title');
$grid->column('status','是否启用')->switch();
$grid->column('sort')->editable()->width(120); $grid->column('sort')->editable()->width(120);
$grid->column('created_at'); $grid->column('created_at');
$grid->column('updated_at'); $grid->column('updated_at');
@ -57,6 +58,7 @@ class NoticeController extends AdminController
$show->field('author'); $show->field('author');
$show->field('title'); $show->field('title');
$show->field('content')->unescape(); $show->field('content')->unescape();
$show->field('status','是否启用');
$show->field('sort'); $show->field('sort');
$show->field('created_at'); $show->field('created_at');
$show->field('updated_at'); $show->field('updated_at');
@ -80,6 +82,7 @@ class NoticeController extends AdminController
$form->text('author')->default(Admin::user()->name); $form->text('author')->default(Admin::user()->name);
$form->text('title')->required(); $form->text('title')->required();
$form->editor('content'); $form->editor('content');
$form->switch('status','是否启用');
$form->text('sort')->default(255); $form->text('sort')->default(255);
})->saving(function (Form $form) { })->saving(function (Form $form) {
//不允许修改非自己的数据 //不允许修改非自己的数据

2
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']); ->orderBy('sort')->orderBy('id', 'desc')->get(['id', 'title']);
# 我的频道 # 我的频道

3
app/Http/Controllers/Api/NoticeController.php

@ -15,6 +15,7 @@ class NoticeController extends Controller
public function index() public function index()
{ {
$list = Notice::query()->where('agent_id', $this->agent_id) $list = Notice::query()->where('agent_id', $this->agent_id)
->status()
->select(['title', 'updated_at']) ->select(['title', 'updated_at'])
->orderBy('id', 'DESC') ->orderBy('id', 'DESC')
->simplePaginate(15); ->simplePaginate(15);
@ -25,7 +26,7 @@ class NoticeController extends Controller
{ {
$id = (int)request()->input('id'); $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) { if (!$data) {
return $this->error('公告不存在或已删除'); return $this->error('公告不存在或已删除');
} }

5
app/Models/Notice.php

@ -7,4 +7,9 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
class Notice extends BaseModel class Notice extends BaseModel
{ {
use HasFactory; use HasFactory;
public function scopeStatus($query)
{
return $query->where('status',1);
}
} }

32
database/migrations/2021_09_18_153814_update_notice_table_table.php

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class UpdateNoticeTableTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('notices', function (Blueprint $table) {
$table->tinyInteger('status')
->default(0)
->comment('是否启用 0禁用 1启用');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
Loading…
Cancel
Save