如何捕获Notification :: send异常?此通知工作正常,但我想添加一些管理页面以查看状态。 Notification :: send方法始终返回null,无论是否成功。 现在完整的代码:
namespace App\Listeners;
use App\Events\SendUserNotification;
use Illuminate\Support\Facades\Notification;
use App\Models\LogNotification;
class SendUserNotificationListener
{
public function handle(SendUserNotification $event)
{
$users = $event->users;
$notification = $event->notification;
$logData = [];
try {
$send = Notification::send($users, $notification); // returned null
$status = "success";
} catch (\Exception $exception) {
$status = "error";
}
foreach ($users as $user) {
$logData[] = [
"user_id" => $user->id,
"type" => $notification->getType(),
"status" => $status,
"created_at" => now(),
"updated_at" => now(),
];
}
LogNotification::insert($logData);
}
}
此代码无法在Notification :: send方法中捕获任何异常。