| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace App\Http\Controllers\Admins;
- use App\Modes\Protocol;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- class ProtocolController extends Controller
- {
- public function index(Request $request)
- {
- /*$validator = \Validator::make($param = $request->all(), [
- ]);
- if ($validator->fails()) {
- return showJsonErr($validator->errors()->first());
- }*/
- $res = Protocol::orderByDesc('created_at')
- ->with(['User' => function ($query) {
- $query->select(['nick_name', 'id']);
- }])
- ->limit(1)->get();
- return showJsonSucc(1001, $res);
- }
- public function add(Request $request)
- {
- $validator = \Validator::make($param = $request->all(), [
- 'title' => 'string|max:255',
- 'content' => 'required',
- ]);
- if ($validator->fails()) {
- return showJsonErr($validator->errors()->first());
- }
- $param['created_uid'] = \Auth::id();
- $param['status'] = 1;
- $protocol = Protocol::first();
- if (empty($protocol)) {
- return \DB::transaction(function () use ($param) {
- // Protocol::whereStatus(1)->update(['status' => 2]);
- $result = Protocol::insert($param);
- if (!$result) {
- return showJsonErr('添加协议失败');
- }
- return showJsonSucc('添加协议成功');
- });
- } else {
- $result = Protocol::whereId($protocol->id)->update($param);
- if (!$result) {
- return showJsonErr('修改协议失败');
- }
- return showJsonSucc('修改协议成功');
- }
-
- }
- }
|