PHP code example of jobmetric / laravel-barcode

1. Go to this page and download the library: Download jobmetric/laravel-barcode library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jobmetric / laravel-barcode example snippets


use JobMetric\Barcode\HasBarcode;

class Product extends Model
{
    use HasBarcode;
}

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

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

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

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

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

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

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

php artisan make:listener AddProductResourceToBarcodableResourceListener

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);
        }
    }
}

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