| 12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
- namespace App\Http\Api;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Str;
- use App\Models\Like;
- use App\Models\Notification;
- class WatchApi
- {
- public static function change($resId, $from, $message, $url)
- {
- //发送站内信
- $watches = Like::where('type', 'watch')
- ->where('target_id', $resId)
- ->get();
- $notifications = [];
- foreach ($watches as $watch) {
- $notifications[] = [
- 'id' => Str::uuid(),
- 'from' => $from,
- 'to' => $watch->user_id,
- 'url' => $url,
- 'content' => $message,
- 'res_type' => $watch->target_type,
- 'res_id' => $watch->target_id,
- 'channel' => Str::uuid(),
- 'created_at' => now(),
- 'updated_at' => now(),
- ];
- }
- Log::debug('notification insert', ['data' => $notifications]);
- $new = Notification::insert($notifications);
- return $new;
- }
- }
|