admin管理员组文章数量:1191739
I’m using Ambengers\QueryFilter\AbstractQueryFilter (Git Repository) in a project. I need to perform a database search and generate a PDF of student logs, but I want to handle this with a job. When I try to pass an object of a class that extends Ambengers\QueryFilter\AbstractQueryFilter, I get the error "Serialization of 'Closure' is not allowed". How can I use AbstractQueryFilter to perform the database search within the job?
Here are the relevant parts of the Job class that are important for the issue:
class CreateStudentLogsPdfJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*/
public function __construct(
public StudentLogsFilters $filters
){}
/**
* Execute the job.
*/
public function handle(): void
{
$studentLogs = StudentLogs::with('user')
->with('discipline')
->where('consumer_id', DomainHelper::getConsumerId())
->orderBy('created_at', 'desc')
->filter($this->filters);
}
}
I’ve attempted to pass just the filter instances and other related data, but without success.
I’ve tried replacing the anonymous functions with explicitly declared functions in the StudentLogsFilters class, but the issue persists.
I’m hoping to continue leveraging the benefits of AbstractQueryFilter, and if necessary, just pass the query builder it creates.
EDIT: I found out that this happens because Ambengers\QueryFilter\AbstractQueryFilter requires a Request attribute in its constructor. I'll explore other approaches.
本文标签:
版权声明:本文标题:How can I pass an AbstractQueryFilter or its filters to a Job in Laravel without encountering the 'Serialization of & 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738408984a2085207.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论