enimiste/laravel-uniqueable-jobs-l54

Laravel 5.4 唯一性作业支持

v5.6.0 2018-02-27 11:50 UTC

This package is auto-updated.

Last update: 2024-08-29 04:57:14 UTC


README

安装

使用以下命令通过 composer 安装此包(Laravel 5.6)

composer require "enimiste/laravel-uniqueable-jobs-l54:5.6.*"

对于 Laravel 5.4

composer require "enimiste/laravel-uniqueable-jobs-l54:5.4.*"

更新 composer 后,将服务提供者添加到 config/app.php 中的 providers 数组中

Com\NickelIT\UniqueableJobs\UniqueableJobsServiceProvider::class,

发布迁移

php artisan queue:table
php artisan vendor:publish  --tag=migrations

在您的作业类中使用 Com\NickelIT\UniqueableJobs\DispatchableCom\NickelIT\UniqueableJobs\Uniqueable 而不是默认的。
注意:此特性应该直接在作业类中使用,而不是在存在的基类中。

为了确保给定的作业在每个模型和模型 ID 中仅存储一次,您可以在作业实例上使用 ->unique(Model::class, $model->id) 或者在调用 dispatch() 方法之后

$u = User::first();
DoSomethingJob::dispatch('Hello from unique job ' . $u->email)
                        ->unique(User::class, $u->id);
DoSomethingJob::dispatch('Hello from unique job ' . $u->email)
                        ->unique(User::class, $u->id);
//In this case the job will be stored once if it was already in the db

许可证

Laravel Uniqueable Jobs 是开源软件,许可协议为 MIT 许可协议