在向Laravel添加可排队的通知时使用Laravel发送通知时发生的问题。环顾了供应商类,但看不到这样做的原因,我什至看不到任何对PDO的引用?如果有人可以帮忙
堆栈跟踪:
(1/1) PDOException
You cannot serialize or unserialize PDO instances
in Queue.php line 139
at PDO->__sleep()
at serialize(object(SendQueuedNotifications))
in Queue.php line 139
at Queue->createObjectPayload(object(SendQueuedNotifications),'queues:users')
in Queue.php line 110
at Queue->createPayloadArray(object(SendQueuedNotifications),'queues:users','')
in RedisQueue.php line 153
at RedisQueue->createPayloadArray(object(SendQueuedNotifications),'')
in Queue.php line 88
at Queue->createPayload(object(SendQueuedNotifications),'')
in RedisQueue.php line 91
at RedisQueue->push(object(SendQueuedNotifications))
in Dispatcher.php line 184
at Dispatcher->pushCommandToQueue(object(RedisQueue),object(SendQueuedNotifications))
in Dispatcher.php line 160
at Dispatcher->dispatchToQueue(object(SendQueuedNotifications))
in Dispatcher.php line 73
at Dispatcher->dispatch(object(SendQueuedNotifications))
in NotificationSender.php line 195
at NotificationSender->queueNotification(array(object(BelongsTo)),object(ThreadStartedWithProfileNotification))
in NotificationSender.php line 74
at NotificationSender->send(array(object(BelongsTo)),object(ThreadStartedWithProfileNotification))
in ChannelManager.php line 39
at ChannelManager->send(object(BelongsTo),object(ThreadStartedWithProfileNotification))
in Facade.php line 237
at Facade::__callStatic('send',array(object(BelongsTo),object(ThreadStartedWithProfileNotification)))
in UserNotification.php line 27
at UserNotification::send(object(BelongsTo),object(ThreadStartedWithProfileNotification))
in CreateController.php line 51
at CreateController->__invoke(object(Request),object(Profile))
at call_user_func_array(array(object(CreateController),'__invoke'),array(object(Request),object(Profile)))
in BoundMethod.php line 32
at BoundMethod::Illuminate\Container\{closure}()
in BoundMethod.php line 90
at BoundMethod::callBoundMethod(object(Application),array(object(CreateController),object(Closure))
in BoundMethod.php line 34
at BoundMethod::call(object(Application),array('profile' => object(Profile)),null)
in Container.php line 576
at Container->call(array(object(CreateController),array('profile' => object(Profile)))
in RoutesRequests.php line 376
at Application->callControllerCallable(array(object(CreateController),array('profile' => object(Profile)))
in RoutesRequests.php line 342
at Application->callLumenController(object(CreateController),'__invoke',array(1,array('uses' => 'App\\Http\\Controllers\\Profile\\Messaging\\CreateController','middleware' => array('unsupported','unacceptable','auth:api')),array('profile' => object(Profile))))
in RoutesRequests.php line 316
at Application->callControlleraction(array(1,array('profile' => object(Profile))))
in RoutesRequests.php line 278
at Application->callactionOnArrayBasedRoute(array(1,array('profile' => object(Profile))))
in RoutesRequests.php line 258
at Application->Laravel\Lumen\Concerns\{closure}(object(Request))
at call_user_func(object(Closure),object(Request))
in Pipeline.php line 52
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request))
in Authenticate.php line 43
at Authenticate->handle(object(Request),object(Closure),'api')
in Pipeline.php line 163
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure),object(Request))
in Pipeline.php line 32
UserNotification::send($profile->user(),new ThreadStartedWithProfileNotification(
$profile,$thread,$accountSending
));
UserNotification:
<?php
declare(strict_types=1);
namespace Shared\Helpers;
use App\Models\User;
use RuntimeException;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Notification;
use Shared\Helpers\Contract\UserNotificationInterface;
/**
* Class UserNotification
* @package Shared\Helpers
*/
class UserNotification
{
/**
* @param $recipients
* @param UserNotificationInterface $notification
* @return void
*/
public static function send($recipients,UserNotificationInterface $notification) : void
{
self::validate($recipients);
Notification::send($recipients,$notification);
}
/**
* @param $recipients
* @param UserNotificationInterface $notification
* @return void
*/
public static function sendNow($recipients,UserNotificationInterface $notification) : void
{
self::validate($recipients);
Notification::sendNow($recipients,$notification);
}
/**
* @param Collection|User $recipients
* @return void
*/
private static function validate($recipients) : void
{
if ($recipients instanceof User) {
return;
}
$recipients->each(function ($recipient) {
if (! $recipient instanceof User) {
throw new RuntimeException(sprintf(
'Recipient must be an instance of App\Models\User,%s given',$recipient
));
}
});
}
}
实际通知:
<?php
declare(strict_types = 1);
namespace App\Notifications\Individual;
use App\Models\account;
use App\Models\Profile;
use App\Models\Thread;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Shared\Helpers\Contract\UserNotificationInterface;
use Shared\Helpers\Helper;
/**
* Class ThreadStartedWithProfile Notification
* @package App\Notifications\Individual
*/
class ThreadStartedWithProfileNotification extends Notification implements ShouldQueue,UserNotificationInterface
{
use Queueable;
/** @var Profile $application */
protected $profile;
/** @var Thread $thread */
protected $thread;
/** @var account $account */
private $account;
/**
* ThreadStartedWithProfileNotification constructor.
* @param Profile $profile
* @param Thread $thread
* @param account $account
*/
public function __construct(Profile $profile,Thread $thread,account $account)
{
$this->profile = $profile;
$this->thread = $thread;
$this->account = $account;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail','database'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->subject("{$this->account->name} Has Messaged You!")
->greeting("Hello")
->line("{$this->account->name} has messaged you on Digital Profile")
->action('View',Helper::url('/messaging'))
;
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
'uuid' => $this->thread->uuid,'account' => [
'uuid' => $this->account->uuid,'name' => $this->account->name,'type' => $this->account->type->key,],];
}
}