2017 © Pedro Peláez
 

library buyable

let laravel model buyable

image

unisharp/buyable

let laravel model buyable

  • Monday, July 2, 2018
  • by youchenlee
  • Repository
  • 9 Watchers
  • 1 Stars
  • 1,259 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 54 % Grown

The README.md

UniSharp Buyable

Latest Version on Packagist ![Software License][ico-license] Build Status ![Coverage Status][ico-scrutinizer] Quality Score ![Total Downloads][ico-downloads], (*1)

Let laravel model buyable, (*2)

Installation

  • Install package, (*3)

    composer require unisharp/buyable dev-master, (*4)

  • Migrate tables, (*5)

    php artisan migrate, (*6)

Usages

Use trait in model, (*7)

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, (*8)

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

Change one of model's spec, (*9)

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

Specified one of model's specs, (*10)

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

$product->specify($spec);

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

$product->specify('Black');

Get all of model's specs, (*11)

$product->specs

The Versions