- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在数据更改时向用户发送广播通知。但是每次我尝试发送通知时,都会收到此错误:array_key_exists(): The first argument should be either a string or an integer
.
这是我的通知:
class MyNotification extends Notification
{
use Queueable;
public $games;
public $title;
public $summary;
public $url;
public function __construct($games)
{
$this->games = $games;
$this->title = "Your games";
$this->summary = "Games for {$games[0]->team}";
$this->url = "/some/url";
}
public function via($notifiable)
{
return ['mail','broadcast','database'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->subject($this->title)
->line($this->summary);
}
/**
* Get the voice representation of the notification.
*
* @param mixed $notifiable
* @return PushMessage
*/
public function toPush($notifiable)
{
// ...
}
public function toBroadcast($notifiable)
{
return new BroadcastMessage($this->toArray($notifiable));
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
'icon' => 'fa fa-calendar',
'text' => $this->summary,
'title' => $this->title,
'url' => $this->url
];
}
}
via
中删除“广播”时阵列,一切正常。我不知道我做错了什么!有人可以帮忙吗?谢谢!
Stack trace:
1. ErrorException->() /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:321
2. array_key_exists() /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:321
3. Illuminate\Database\Eloquent\Model->getAttribute() /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1396
4. Illuminate\Database\Eloquent\Model->getKey() /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1406
5. Illuminate\Database\Eloquent\Model->getQueueableId() /var/www/html/vendor/laravel/framework/src/Illuminate/Support/HigherOrderCollectionProxy.php:60
6. Illuminate\Support\HigherOrderCollectionProxy->Illuminate\Support\{closure}() [internal]:0
7. array_map() /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Collection.php:638
8. Illuminate\Support\Collection->map() /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Collection.php:254
9. Illuminate\Database\Eloquent\Collection->map() /var/www/html/vendor/laravel/framework/src/Illuminate/Support/HigherOrderCollectionProxy.php:61
10. Illuminate\Support\HigherOrderCollectionProxy->__call() /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Collection.php:549
11. Illuminate\Database\Eloquent\Collection->getQueueableIds() /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php:25
12. Illuminate\Notifications\Notification->getSerializedPropertyValue() /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/SerializesModels.php:23
13. Illuminate\Notifications\Notification->__sleep() [internal]:0
14. serialize() /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Queue.php:139
15. Illuminate\Queue\Queue->createObjectPayload() /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Queue.php:110
16. Illuminate\Queue\Queue->createPayloadArray() /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Queue.php:88
17. Illuminate\Queue\Queue->createPayload() /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/SyncQueue.php:40
18. Illuminate\Queue\SyncQueue->push() /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Queue.php:44
19. Illuminate\Queue\Queue->pushOn() /var/www/html/vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastManager.php:127
20. Illuminate\Broadcasting\BroadcastManager->queue() /var/www/html/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:267
21. Illuminate\Events\Dispatcher->broadcastEvent() /var/www/html/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:190
22. Illuminate\Events\Dispatcher->dispatch() /var/www/html/vendor/laravel/framework/src/Illuminate/Notifications/Channels/BroadcastChannel.php:51
23. Illuminate\Notifications\Channels\BroadcastChannel->send() /var/www/html/vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php:146
24. Illuminate\Notifications\NotificationSender->sendToNotifiable() /var/www/html/vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php:105
25. Illuminate\Notifications\NotificationSender->Illuminate\Notifications\{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Traits/Localizable.php:19
26. Illuminate\Notifications\NotificationSender->withLocale() /var/www/html/vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php:107
27. Illuminate\Notifications\NotificationSender->sendNow() /var/www/html/vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php:79
28. Illuminate\Notifications\NotificationSender->send() /var/www/html/vendor/laravel/framework/src/Illuminate/Notifications/ChannelManager.php:39
29. Illuminate\Notifications\ChannelManager->send() /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:261
30. Illuminate\Support\Facades\Facade->__callStatic() /var/www/html/app/Http/Controllers/Basketball/BasketballGameController.php:458
31. App\Http\Controllers\Basketball\BasketballGameController->updateJudges() /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
32. call_user_func_array() /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
33. Illuminate\Routing\Controller->callAction() /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:45
34. Illuminate\Routing\ControllerDispatcher->dispatch() /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php:219
35. Illuminate\Routing\Route->runController() /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php:176
36. Illuminate\Routing\Route->run() /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php:681
37. Illuminate\Routing\Router->Illuminate\Routing\{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:130
38. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php:43
39. Illuminate\Auth\Middleware\Authenticate->handle() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171
40. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() /var/www/html/vendor/barryvdh/laravel-cors/src/HandleCors.php:58
41. Barryvdh\Cors\HandleCors->handle() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171
42. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php:41
43. Illuminate\Routing\Middleware\SubstituteBindings->handle() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171
44. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php:59
45. Illuminate\Routing\Middleware\ThrottleRequests->handle() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171
46. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:105
47. Illuminate\Pipeline\Pipeline->then() /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php:683
48. Illuminate\Routing\Router->runRouteWithinStack() /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php:658
49. Illuminate\Routing\Router->runRoute() /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php:624
50. Illuminate\Routing\Router->dispatchToRoute() /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php:613
51. Illuminate\Routing\Router->dispatch() /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:170
52. Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:130
53. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() /var/www/html/vendor/fideloper/proxy/src/TrustProxies.php:57
54. Fideloper\Proxy\TrustProxies->handle() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171
55. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21
56. Illuminate\Foundation\Http\Middleware\TransformsRequest->handle() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171
57. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27
58. Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171
59. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:62
60. Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171
61. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() /var/www/html/vendor/barryvdh/laravel-cors/src/HandleCors.php:58
62. Barryvdh\Cors\HandleCors->handle() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171
63. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:105
64. Illuminate\Pipeline\Pipeline->then() /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:145
65. Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter() /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:110
66. Illuminate\Foundation\Http\Kernel->handle() /var/www/html/public/index.php:55
$this->games = $games;
, 并编辑
$this->summary
到一些字符串 - 它有效!
$games
是模型
Game
的集合.
最佳答案
如果我理解正确,原因很简单,因为您的模型使用复合键 not supported by eloquent .
所以这就是我认为在我对整个通知/广播模块的了解有限的情况下实际发生的事情。
MyNotification
事件入队Notification
您从中扩展的基类实际上实现了 Illuminate\Queue\SerializesModels
trait 等会自动尝试序列化通知类属性中的所有模型 Game
集合时对象,然后集合尝试调用 getQueueableId
在集合中的每个模型上,然后失败,因为它尝试根据您的复合键 // in Game model
protected $primaryKey = 'id';
broadcastWith
您的
MyNotification
上的方法类,虽然我不确定这是否会绕过
SerializeModels
的序列化方法特征。
// in MyNotification
public function broadcastWith()
{
return ['id' => $this->id];
}
$this->games
使用集合,您可以将其转换为数组。毕竟,最后,你的
toBroadcast
方法是实际控制广播的方法。
$this->games = $games->toArray();
getQueueableId()
你的方法
Game
模型。
// in Game Model
public function getQueueableId()
{
return $this->id;
// or if you still want to utilize your composite keys. UNTESTED
return $this->key_one.$this->key_two;
}
关于Laravel 广播通知 - 尝试发送通知时出现错误 "array_key_exists()",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60532680/
说真的,你怎么能在不发疯的情况下处理所有这些异常呢?我是不是读了太多关于异常处理的文章或什么?我尝试重构了几次,但每次似乎都以更糟糕的结果告终。也许我应该承认确实会发生异常(exception)情况,
背景 两者 try/rescue和 try/catch是 Elixir 中的错误处理技术。根据 corresponding chapter在介绍指南中。 Errors can be rescued u
每当我尝试在 Raspberry PI 上运行此 python 脚本时,我都会遇到问题: import socket import sys # Create a TCP/IP socket sock
我想知道一些关于 PHP 的 try , catch声明。 让我们考虑以下示例。 abstract class ExceptionA extends Exception {} class Except
我的 laravel v5.4 项目中有两个模型,user 和 admin。 在 config/auth.php 中,我向守卫和提供者添加了管理员,如下所示: 'guards' => [ 'w
try: r = requests.get(url, params={'s': thing}) except requests.ConnectionError, e: print e
我有以下代码。 但是,它并不能捕获所有错误,而我仍然会收到“throw er;//未处理的'错误'事件”。 为什么是这样? app.post('/api/properties/zip/:zip/bed
问题与细节 我正在使用自定义错误处理,遇到的错误之一是“路径中的非法字符”。我有一个自定义函数,旨在通过路径字符串查找此类非法字符,并在找到它们时引发自定义错误。但是我发现,取决于非法字符,Test-
This question already has answers here: How do I catch a numpy warning like it's an exception (not j
我正在使用其他人的代码,但我不熟悉try/catch,因此我举了一个类似的小例子。在第11行上,如果我写了error(''),似乎没有发现错误并增加了索引j。但是,编写error(' ')或error
我在我的一个程序中遇到了这个问题,在这种情况下,尝试/异常(exception)的错误使程序变得更好,以防用户意外输入了他们不应该输入的内容。它仍然给我错误,我为为什么感到困惑。如果对我的问题确实很重
我在尝试TRY ... CATCH块时遇到问题。有人可以解释为什么以下代码无法执行我的sp吗? DECLARE @Result int SET @Result = 0 BEGIN TRY SE
我有一个相当大的 powershell 脚本,其中包含许多(20 多个)执行各种操作的函数。 现在所有代码实际上都没有任何错误处理或重试功能。如果某个特定的任务/功能失败,它就会失败并继续。 我想改进
为什么我尝试时需要导入 inputmismatchException catch(InputMismatchException e){ System.out.println("
我对此感到困惑 - 我为辅助方法编写了一个 try/catch 。它的目的是捕获任何无效输入(任何不是“男性”或“女性”的内容(没有特定情况)。如果输入无效,它将通知用户,然后让他们重试。如果有效,则
我有时会发现自己处于如下场景。尽可能简单地陈述问题 “有时我会创建一段代码,Java 让我将其包含在 try/catch 语句中。我没有使用 catch,所以我将其留空。为什么这是错误的?” boo
我有点困惑为什么当我不使用 Try block 时会出现 Try block 错误。 我在代码块底部附近收到错误通知。如果我不使用 try/catch,有人可以向我解释为什么会发生这种情况吗? 它是否
我已经盯着我的电脑两个小时了,我不知道我做错了什么。谁能帮助我看到光明? package blackjack; import java.util.Random; import java.util.Sc
我想将方法保存在 Enum 中,但 Class.getDeclaredMethod 抛出 NoSuchMethodException,那么我该如何处理呢?我的代码: public enum Car
这个问题已经有答案了: Executing multi-line statements in the one-line command-line (18 个回答) 已关闭 3 年前。 如何使用try.
我是一名优秀的程序员,十分优秀!