PHP code example of unisharp / buyable

1. Go to this page and download the library: Download unisharp/buyable 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/ */

    

unisharp / buyable example snippets

 artisan migrate

namespace App;

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

class Product extends Model
{
    use Buyable;
}

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

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

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

$product->specify($spec);

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

$product->specify('Black');

$product->specs