unisharp/buyable

let laravel model buyable

Package info

github.com/UniSharp/buyable

pkg:composer/unisharp/buyable

Statistics

Installs: 2 084

Dependents: 1

Suggesters: 0

Stars: 3

Open Issues: 0

0.0.9 2018-03-21 08:36 UTC

Requires

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT ecfc16d42e13a50f36feca2b99882d88dd167cd0

  • UniSharp <opensource.woop@unisharp.com>

categoryUniSharp

This package is auto-updated.

Last update: 2026-06-22 01:07:28 UTC


README

👁 Latest Version on Packagist
👁 Software License
👁 Build Status
👁 Coverage Status
👁 Quality Score
👁 Total Downloads

Let laravel model buyable

Installation

  • Install package

    composer require unisharp/buyable dev-master

  • Migrate tables

    php artisan migrate

Usages

Use trait in model

namespace App;

use Illuminate\Database\Eloquent\Model;
use UniSharp\Buyable\Traits;

class Product extends Model
{
 use Buyable;
}

Create model and model's specs at the same time

Product::create([
 'name' => 'product A',
 'spec' => 'Black',
 'price' => 20,
 'stock' => 5,
 'sku' => 'B-1',
 'sold_qty' => 2
]);

Change one of model's spec

$product->price = 1;
$product->stock = 1;
$product->sku = 'B-2';
$product->sold_qty = 2;
$product->save();

Specified one of model's specs

$spec = Spec::where('name', 'Black')->first();

$product->specify($spec);

$product->specify($spec->id);

$product->specify('Black');

Get all of model's specs

$product->specs