我有一个系统可以让用户将他们的银行对账单导入为 CSV 文件。导入在后台作为作业排队。但是,我想通知用户让他们知道他们的导入何时完成。如何使用 Laravel 队列和通知来做到这一点?
更新:
我尝试使用以下代码将 JobProcessed 获取到获取正在运行的命令$event
的方法:AppServiceProvider@boot
Queue::after(function (JobProcessed $event) {
$cmd = unserialize( json_decode( $event->job->getRawBody() )->data->command );
dd( $cmd );
});
这将返回以下转储。但是,我不知道如何获取account > attributes > user_id
:
App\Jobs\TestJob {#730
#account: App\Account {#750
#fillable: array:3 [
0 => "name"
1 => "number"
2 => "bank"
]
#connection: "sqlite"
#table: "accounts"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:7 [
"id" => "1"
"created_at" => "2019-12-12 12:25:16"
"updated_at" => "2019-12-12 12:25:16"
"user_id" => "1"
"name" => "Customer Name"
"number" => "Bank Number"
"bank" => "Bank Name"
]
#original: array:7 [
"id" => "1"
"created_at" => "2019-12-12 12:25:16"
"updated_at" => "2019-12-12 12:25:16"
"user_id" => "1"
"name" => "Customer Name"
"number" => "Bank Number"
"bank" => "Bank Name"
]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [
0 => "*"
]
}
#job: null
+connection: null
+queue: null
+chainConnection: null
+chainQueue: null
+delay: null
+middleware: []
+chained: []
}
更新 2:
解决了。我的工作声明$this->account
为protected
,并且需要对其进行设置public
才能访问。