unisharp / buyable
let laravel model buyable
Installs: 2 082
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 11
Forks: 0
Open Issues: 0
Requires
- php: ^7.0
- illuminate/config: >5.5.0
- illuminate/database: >5.5.0
- illuminate/support: >5.5.0
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.6.0
- mockery/mockery: ^0.9.4
- orchestra/database: ~3.6.0
- orchestra/testbench: ~3.6.0
- phpunit/phpunit: ^7.0
- sebastian/diff: ^3.0.0
README
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