【发布时间】:2018-09-26 14:45:38
【问题描述】:
我有一个 Laravel 5.4 应用程序。
我的问题是我每周有一份工作要排队处理一些电子邮件。
像这样:
Mail::to($user)->queue(new \App\Mail\INBND10\i01($user));
一切看起来都很好,一些电子邮件已送达,但在发送了几封电子邮件后,我得到了一个尝试获取非对象属性异常。
Sentry 告诉我这是在 Mail 构建方法中,如下所示:
有什么想法会导致这种奇怪的行为吗?
编辑
堆栈跟踪
ErrorException: Trying to get property of non-object
#40 vendor/laravel/framework/src/Illuminate/Mail/Mailable.php(462): handleError
#39 vendor/sentry/sentry/lib/Raven/Breadcrumbs/ErrorHandler.php(34): handleError
#38 vendor/laravel/framework/src/Illuminate/Mail/Mailable.php(462): setAddress
#37 vendor/laravel/framework/src/Illuminate/Mail/Mailable.php(346): from
#36 app/Mail/INBND10/i01.php(35): build
#35 app/Mail/INBND10/i01.php(0): call_user_func_array
#34 vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): Illuminate\Container\{closure}
#33 vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): callBoundMethod
#32 vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): call
#31 vendor/laravel/framework/src/Illuminate/Container/Container.php(539): call
#30 vendor/laravel/framework/src/Illuminate/Mail/Mailable.php(116): send
#29 vendor/laravel/framework/src/Illuminate/Mail/SendQueuedMailable.php(52): handle
#28 vendor/laravel/framework/src/Illuminate/Mail/SendQueuedMailable.php(0): call_user_func_array
#27 vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): Illuminate\Container\{closure}
#26 vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): callBoundMethod
#25 vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): call
#24 vendor/laravel/framework/src/Illuminate/Container/Container.php(539): call
#23 vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(94): Illuminate\Bus\{closure}
#22 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(114): Illuminate\Pipeline\{closure}
#21 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): then
#20 vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(98): dispatchNow
#19 vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(42): call
#18 vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(69): fire
#17 vendor/laravel/framework/src/Illuminate/Queue/Worker.php(317): process
#16 vendor/laravel/framework/src/Illuminate/Queue/Worker.php(267): runJob
#15 vendor/laravel/framework/src/Illuminate/Queue/Worker.php(113): daemon
#14 vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(101): runWorker
#13 vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(85): fire
#12 vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(0): call_user_func_array
#11 vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): Illuminate\Container\{closure}
#10 vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): callBoundMethod
#9 vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): call
#8 vendor/laravel/framework/src/Illuminate/Container/Container.php(539): call
#7 vendor/laravel/framework/src/Illuminate/Console/Command.php(182): execute
#6 vendor/symfony/console/Command/Command.php(251): run
#5 vendor/laravel/framework/src/Illuminate/Console/Command.php(167): run
#4 vendor/symfony/console/Application.php(946): doRunCommand
#3 vendor/symfony/console/Application.php(248): doRun
#2 vendor/symfony/console/Application.php(148): run
#1 vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(122): handle
#0 artisan(35): null
【问题讨论】:
-
你能粘贴错误的堆栈跟踪吗?
-
如果您尝试访问父对象的可选属性,通常会发生这种情况,例如
$user->image->id;如果$user->image是null,并且您在尝试访问->id之前没有检查,您将遇到该错误。这只是一个例子;寻找链接的->访问权限,尤其是在view中,并确认您的逻辑。 -
@Paras 我已经用堆栈跟踪更新了 OP
标签: laravel queue laravel-5.4