WatchApi.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Http\Api;
  3. use Illuminate\Support\Facades\Log;
  4. use Illuminate\Support\Str;
  5. use App\Models\Like;
  6. use App\Models\Notification;
  7. class WatchApi
  8. {
  9. public static function change($resId, $from, $message, $url)
  10. {
  11. //发送站内信
  12. $watches = Like::where('type', 'watch')
  13. ->where('target_id', $resId)
  14. ->get();
  15. $notifications = [];
  16. foreach ($watches as $watch) {
  17. $notifications[] = [
  18. 'id' => Str::uuid(),
  19. 'from' => $from,
  20. 'to' => $watch->user_id,
  21. 'url' => $url,
  22. 'content' => $message,
  23. 'res_type' => $watch->target_type,
  24. 'res_id' => $watch->target_id,
  25. 'channel' => Str::uuid(),
  26. 'created_at' => now(),
  27. 'updated_at' => now(),
  28. ];
  29. }
  30. Log::debug('notification insert', ['data' => $notifications]);
  31. $new = Notification::insert($notifications);
  32. return $new;
  33. }
  34. }