Download the PHP package binary-cats/laravel-sku without Composer
On this page you can find all versions of the php package binary-cats/laravel-sku. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download binary-cats/laravel-sku
More information about binary-cats/laravel-sku
Files in binary-cats/laravel-sku
Package laravel-sku
Short Description Generate SKUs for Eloquent models
License MIT
Homepage https://github.com/binary-cats/laravel-sku
Informations about the package laravel-sku
Handle SKUs for your models
Generate unique SKUs when saving any Eloquent model.
Package will add a new method to Laravel's Illuminate\Support\Str::sku() class to generate an SKU for you.
Installation
Minimum requirements:
- Laravel 12+
- PHP 8.2+
You can install the package via composer:
Upgrading from previous versions should be minimal. However, if you extend or replace the base classes, please make sure to review the changes.
For older versions of Laravel, use version 0.8:
The service provider will automatically register itself.
You can publish the config file with:
This is the contents of the config file that will be published at config/laravel-sku.php:
Please note that the above set up expects you have an sku field in your model. If you plan to manually overwrite the values, please make sure to add this field to fillable array;
Usage
Add BinaryCats\Sku\HasSku trait to your model. That's it!
Behind the scenes this will register an observer for the sku field, which will be generated every time you save the model.
Advanced usage
If you want to change settings for a specific model, you can overload the skuOptions() method:
Custom Generator
Assuming you want some extra logic, like having a default value, or defining prefix for an SKU,
you can implement your own SkuGenerator. It is easiest to extend the base class, but you are free to explore any which way.
First, create a custom class:
and then update generator config value:
You can also opt out to change implementation completely;
just remember that custom generator must implement BinaryCats\Sku\Contracts\SkuGenerator.
About SKUs
Stock Keeping Unit allows you to set a unique identifier or code that refers to the particular stock keeping unit.
Testing
Changelog
Please see CHANGELOG for more information about what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using issue tracker.
Postcardware
You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
Credits
- Cyrill Kalita
- All Contributors
Support us
Binary Cats is a webdesign agency based in Illinois, US.
License
The MIT License (MIT). Please see License File for more information.