2019-12-12 13:45:46 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
use App\Http\Requests\Admin\NoticeSave;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Models\Notice;
|
|
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
|
|
|
|
|
class NoticeController extends Controller
|
|
|
|
{
|
|
|
|
public function index (Request $request) {
|
|
|
|
return response([
|
2019-12-12 14:39:26 +08:00
|
|
|
'data' => Notice::orderBy('id', 'DESC')->get()
|
2019-12-12 13:45:46 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function save (NoticeSave $request) {
|
|
|
|
$data = $request->only([
|
|
|
|
'title',
|
|
|
|
'content'
|
|
|
|
]);
|
2019-12-12 14:20:47 +08:00
|
|
|
if (!Notice::create($data)) {
|
|
|
|
abort(500, '保存失败');
|
|
|
|
}
|
2019-12-12 13:45:46 +08:00
|
|
|
return response([
|
2019-12-12 14:20:47 +08:00
|
|
|
'data' => true
|
2019-12-12 13:45:46 +08:00
|
|
|
]);
|
|
|
|
}
|
2019-12-12 14:34:28 +08:00
|
|
|
|
|
|
|
public function update (NoticeSave $request) {
|
|
|
|
$data = $request->only([
|
|
|
|
'title',
|
|
|
|
'content'
|
|
|
|
]);
|
|
|
|
if (!Notice::where('id', $request->input('id'))->update($data)) {
|
|
|
|
abort(500, '保存失败');
|
|
|
|
}
|
|
|
|
return response([
|
|
|
|
'data' => true
|
|
|
|
]);
|
|
|
|
}
|
2019-12-12 13:45:46 +08:00
|
|
|
}
|