定制 jobmetric/laravel-barcode 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jobmetric/laravel-barcode

Composer 安装命令:

composer require jobmetric/laravel-barcode

包简介

This is a barcode management package for Laravel that you can use in your projects.

README 文档

README

Contributors Forks Stargazers MIT License LinkedIn

Barcode for laravel

This is a barcode management package for Laravel that you can use in your projects.

Install via composer

Run the following command to pull in the latest version:

composer require jobmetric/laravel-barcode

Documentation

Undergoing continuous enhancements, this package evolves each day, integrating an array of diverse features. It stands as an indispensable asset for enthusiasts of Laravel, offering a seamless way to harmonize their projects with barcode database models.

In this package, you can employ it seamlessly with any model requiring database barcode.

Now, let's delve into the core functionality.

Before doing anything, you must migrate after installing the package by composer.

php artisan migrate

Meet the HasBarcode class, meticulously designed for integration into your model. This class automates essential tasks, ensuring a streamlined process for:

In the first step, you need to connect this class to your main model.

use JobMetric\Barcode\HasBarcode;

class Product extends Model
{
    use HasBarcode;
}

How is it used?

Storing a barcode

You can now use the HasBarcode class to store barcodes for your model. The following example shows how to create a new product by saving a barcode:

$product = new Product();
$product->name = 'Product 1';
$product->save();

$product->storeBarcode('ean13', '1234567890123');

In this example, we created a new product and saved it to the database. Then, we stored a barcode for the product using the storeBarcode method. The first parameter is the barcode type, and the second parameter is the barcode value.

Retrieving a barcode

You can retrieve a barcode for a model using the getBarcode method. The following example shows how to retrieve a barcode for a product:

$product = Product::find(1);
$barcode = $product->getBarcode('ean13');

In this example, we retrieved a product from the database and then retrieved the barcode for the product using the getBarcode method. The parameter is the barcode type.

Deleting a barcode

You can delete a barcode for a model using the deleteBarcode method. The following example shows how to delete a barcode for a product:

$product = Product::find(1);
$product->forgetBarcode('ean13');

In this example, we retrieved a product from the database and then deleted the barcode for the product using the forgetBarcode method. The parameter is the barcode type.

Delete all barcodes

You can delete all barcodes for a model using the deleteAllBarcodes method. The following example shows how to delete all barcodes for a product:

$product = Product::find(1);
$product->forgetAllBarcodes();

In this example, we retrieved a product from the database and then deleted all barcodes for the product using the forgetAllBarcodes method.

Checking if a barcode exists

You can check if a barcode exists for a model using the hasBarcode method. The following example shows how to check if a barcode exists for a product:

$product = Product::find(1);
$exists = $product->hasBarcode('ean13');

In this example, we retrieved a product from the database and then checked if a barcode exists for the product using the hasBarcode method. The parameter is the barcode type.

Updating a barcode

You can update a barcode for a model using the storeBarcode method. The following example shows how to update a barcode for a product:

$product = Product::find(1);
$product->storeBarcode('ean13', '1234567890124');

In this example, we retrieved a product from the database and then updated the barcode for the product using the storeBarcode method. The first parameter is the barcode type, and the second parameter is the new barcode value.

Add barcodeable attribute in Resource

In the barcode resource, there is a field called bacodeable that can display your model, but it must be set as follows.

First, you create a listener for the model you want to display in the barcode resource.

php artisan make:listener AddProductResourceToBarcodableResourceListener

Then, you add the following code to the listener.

use JobMetric\Barcode\Events\BarcodeableResourceEvent;

class AddProductResourceToBarcodableResourceListener
{
    public function handle(BarcodeableResourceEvent $event)
    {
        $barcodeable = $event->barcodeable;

        if ($barcodeable instanceof \App\Models\Product) {
            $event->resource = new \App\Http\Resources\ProductResource($barcodeable);
        }
    }
}

Finally, you add the listener to the EventServiceProvider class.

protected $listen = [
    \JobMetric\Barcode\Events\BarcodeableResourceEvent::class => [
        \App\Listeners\AddProductResourceToBarcodableResourceListener::class,
    ],
];

The work is done, now when the BarcodeResource is called and if the ProductResource should be returned, the details of that resource will be displayed in the barcodeable attribute.

Barcode Types

This package supports the following barcode types:

  • code128
  • code39
  • code93
  • codabar
  • ean13
  • ean8
  • upc
  • upcext
  • isbn
  • datamatrix
  • pdf417
  • qrcode
  • itf14
  • interleaved2of5
  • postnet
  • msi
  • pharmacode
  • maxicode
  • aztec
  • code11
  • code128a
  • code128b
  • code128c
  • code39extended
  • code39mod43
  • code93extended
  • gs1_128
  • gs1_128composite
  • gs1_cc
  • gs1datamatrix
  • gs1datamatrixrectangular
  • gs1qrcode

Events

This package contains several events for which you can write a listener as follows

Event Description
BarcodeStoredEvent This event is called after storing the barcode.
BarcodeUpdateEvent This event is called after updating the barcode.
BarcodeForgetEvent This event is called after forgetting the barcode.

Contributing

Thank you for considering contributing to the Laravel Barcode! The contribution guide can be found in the CONTRIBUTING.md.

License

The MIT License (MIT). Please see License File for more information.

jobmetric/laravel-barcode 适用场景与选型建议

jobmetric/laravel-barcode 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 29 次下载、GitHub Stars 达 14, 最近一次更新时间为 2024 年 06 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「package」 「management」 「barcode」 「laravel」 「jobmetric」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jobmetric/laravel-barcode 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jobmetric/laravel-barcode 我们能提供哪些服务?
定制开发 / 二次开发

基于 jobmetric/laravel-barcode 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 29
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 20
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 14
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-05