PHPackages                             bernardomacedo/laravel-skuable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. bernardomacedo/laravel-skuable

ActiveLibrary

bernardomacedo/laravel-skuable
==============================

Generate product SKU codes for eloquent models.

1.4(7y ago)228[2 issues](https://github.com/bernardomacedo/laravel-skuable/issues)MITPHPPHP &gt;=7.0.0

Since Aug 15Pushed 7y ago2 watchersCompare

[ Source](https://github.com/bernardomacedo/laravel-skuable)[ Packagist](https://packagist.org/packages/bernardomacedo/laravel-skuable)[ Docs](https://github.com/bernardomacedo/laravel-skuable)[ RSS](/packages/bernardomacedo-laravel-skuable/feed)WikiDiscussions master Synced yesterday

READMEChangelog (5)Dependencies (4)Versions (11)Used By (0)

Generate Skus when saving Eloquent models
=========================================

[](#generate-skus-when-saving-eloquent-models)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ef6b3af3ac9f97bec2048c74536071facc6e98679bb785b407a8494cbcf21705/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f4265726e6172646f6d616365646f2f6c61726176656c2d536b7561626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Bernardomacedo/laravel-Skuable)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/6f1324776210ad27a39390e1eac93fe175915f901e9ca464eff2aac9d2dc35bd/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f4265726e6172646f6d616365646f2f6c61726176656c2d536b7561626c652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/Bernardomacedo/laravel-Skuable)[![Quality Score](https://camo.githubusercontent.com/37876f1ef36885a876ba51b0dcf672c894fadafb5296d143c1f42f179b42f82a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f4265726e6172646f6d616365646f2f6c61726176656c2d536b7561626c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Bernardomacedo/laravel-Skuable)[![StyleCI](https://camo.githubusercontent.com/63cf9ea39b289cd4bcdabffa5e546d9316202cfc44dc712b3cb8988b3414b7a5/68747470733a2f2f7374796c6563692e696f2f7265706f732f34383531323536312f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/48512561)[![Total Downloads](https://camo.githubusercontent.com/550b3e562c2ef84e5c3f54b8acdf2187070ae73b74b660a392bfefc1cd099806/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f4265726e6172646f6d616365646f2f6c61726176656c2d536b7561626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Bernardomacedo/laravel-Skuable)

This package provides a trait that will generate a unique Sku when saving any Eloquent model.

```
$model = new EloquentModel();
$model->name = 'activerecord is awesome';
$model->save();

echo $model->Sku; // ouputs "ACT-7655677"
```

The Skus are generated with Laravels `Str::Sku` method, whereby spaces are converted to '-'.

Bernardomacedo is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://Bernardomacedo.be/opensource).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require bernardomacedo/laravel-skuable
```

Usage
-----

[](#usage)

Your Eloquent models should use the `Bernardomacedo\Skuable\HasSku` trait and the `Bernardomacedo\Skuable\SkuOptions` class.

The trait contains an abstract method `getSkuOptions()` that you must implement yourself.

Here's an example of how to implement the trait:

```
