NotificationController.php
1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace App\Http\Container\AppSection\Controllers;
use App\Helpers\JsonResource;
use App\Models\Notification;
use App\Models\NotificationUser;
use App\Support\Controller;
use Auth;
use Illuminate\Contracts\View\View;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class NotificationController extends Controller
{
/**
* @param \App\Models\Notification $notification
* @return \Illuminate\Contracts\View\View
*/
public function show(Notification $notification): View
{
return view('notification', $notification);
}
/**
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function store(Request $request): JsonResponse
{
$request->validate(['ids' => 'required|array', 'ids.*' => 'numeric'], ['*.required' => '参数异常']);
NotificationUser::query()
->where('user_id', Auth::id())->whereIn('notification_id', $request->get('ids'))
->whereNull('read_at')->update(['read_at' => now()->toDateTimeString()]);
return JsonResource::success(JsonResource::UPDATE_SUCCESS);
}
}