Browse Source

1、公告列表改为分页调用;2、增加show方法;

dev
李可松 5 years ago
parent
commit
e600eafcef
  1. 21
      app/Http/Controllers/Api/NoticeController.php

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

@ -11,9 +11,28 @@ use App\Models\Notice;
*/
class NoticeController extends Controller
{
// 公告列表
public function index()
{
$list = Notice::limit(10)->get(['title', 'updated_at']);
$page = request()->input('page');
if ($page && !ctype_digit($page)) {
return $this->error('页码错误');
}
$list = Notice::where('agent_id', $this->agent_id)->select(['title', 'updated_at'])->simplePaginate(15);
return $this->success($list);
}
public function show()
{
$id = request()->input('id');
if (!$id || !ctype_digit($id)) {
return $this->error('无效的ID');
}
$data = Notice::where('agent_id', $this->agent_id)->find($id);
if (!$data) {
return $this->error('公告不存在或已删除');
}
return $this->success($data);
}
}
Loading…
Cancel
Save