From c688f18ac8d00b687b4b1d24f2fc363a9b11245e Mon Sep 17 00:00:00 2001 From: Sam Chen Date: Sun, 26 Dec 2021 22:07:09 +0800 Subject: [PATCH] product sku model --- .../Controllers/Shop/ProductsController.php | 3 +- app/Models/Product.php | 7 ++- app/Models/ProductSku.php | 13 +++++ database/factories/ProductFactory.php | 25 ++++++++++ database/factories/ProductSkuFactory.php | 26 ++++++++++ .../2014_10_12_000000_create_users_table.php | 36 ------------- ...12_100000_create_password_resets_table.php | 32 ------------ ...01_create_personal_access_tokens_table.php | 36 ------------- .../2021_12_26_111435_create_tables.php | 50 +++++++++++++++++++ 9 files changed, 122 insertions(+), 106 deletions(-) create mode 100644 app/Models/ProductSku.php create mode 100644 database/factories/ProductFactory.php create mode 100644 database/factories/ProductSkuFactory.php delete mode 100644 database/migrations/2014_10_12_000000_create_users_table.php delete mode 100644 database/migrations/2014_10_12_100000_create_password_resets_table.php delete mode 100644 database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php create mode 100644 database/migrations/2021_12_26_111435_create_tables.php diff --git a/app/Http/Controllers/Shop/ProductsController.php b/app/Http/Controllers/Shop/ProductsController.php index e88d2346..adfda7e6 100644 --- a/app/Http/Controllers/Shop/ProductsController.php +++ b/app/Http/Controllers/Shop/ProductsController.php @@ -10,6 +10,7 @@ class ProductsController extends Controller { public function show(Request $request, Product $product) { - + $product->load('skus'); + dd($product); } } diff --git a/app/Models/Product.php b/app/Models/Product.php index 22949369..73e7f9b0 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -9,5 +9,10 @@ class Product extends Model { use HasFactory; - protected $fillable = ['price', 'status']; + protected $fillable = ['image', 'video', 'sort_order', 'status', 'variable']; + + public function skus() + { + return $this->hasMany(ProductSku::class); + } } diff --git a/app/Models/ProductSku.php b/app/Models/ProductSku.php new file mode 100644 index 00000000..167e78e2 --- /dev/null +++ b/app/Models/ProductSku.php @@ -0,0 +1,13 @@ + 0, + 'image' => 'path/to/image.jpg', + 'video' => '', + 'sort_order' => 0, + 'status' => true, + 'variable' => '', + ]; + } +} diff --git a/database/factories/ProductSkuFactory.php b/database/factories/ProductSkuFactory.php new file mode 100644 index 00000000..d7f8e75b --- /dev/null +++ b/database/factories/ProductSkuFactory.php @@ -0,0 +1,26 @@ + 0, + 'image' => '', + 'model' => $this->faker->isbn10(), + 'sku' => $this->faker->isbn10(), + 'price' => $this->faker->numberBetween(10, 100), + 'quantity' => $this->faker->numberBetween(1, 100), + 'is_default' => true, + ]; + } +} diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php deleted file mode 100644 index 621a24eb..00000000 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ /dev/null @@ -1,36 +0,0 @@ -id(); - $table->string('name'); - $table->string('email')->unique(); - $table->timestamp('email_verified_at')->nullable(); - $table->string('password'); - $table->rememberToken(); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('users'); - } -} diff --git a/database/migrations/2014_10_12_100000_create_password_resets_table.php b/database/migrations/2014_10_12_100000_create_password_resets_table.php deleted file mode 100644 index 0ee0a36a..00000000 --- a/database/migrations/2014_10_12_100000_create_password_resets_table.php +++ /dev/null @@ -1,32 +0,0 @@ -string('email')->index(); - $table->string('token'); - $table->timestamp('created_at')->nullable(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('password_resets'); - } -} diff --git a/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php b/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php deleted file mode 100644 index 4315e16a..00000000 --- a/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php +++ /dev/null @@ -1,36 +0,0 @@ -id(); - $table->morphs('tokenable'); - $table->string('name'); - $table->string('token', 64)->unique(); - $table->text('abilities')->nullable(); - $table->timestamp('last_used_at')->nullable(); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('personal_access_tokens'); - } -} diff --git a/database/migrations/2021_12_26_111435_create_tables.php b/database/migrations/2021_12_26_111435_create_tables.php new file mode 100644 index 00000000..175e08b7 --- /dev/null +++ b/database/migrations/2021_12_26_111435_create_tables.php @@ -0,0 +1,50 @@ +id()->startingValue(100_000); + $table->string('image'); + $table->string('video'); + $table->integer('sort_order'); + $table->boolean('status'); + $table->json('variable'); + $table->timestamps(); + $table->softDeletes(); + }); + + Schema::create('product_skus', function (Blueprint $table) { + $table->id()->startingValue(100_000); + $table->unsignedBigInteger('product_id'); + $table->string('image'); + $table->string('model'); + $table->string('sku'); + $table->double('price'); + $table->integer('quantity'); + $table->boolean('is_default'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('products'); + Schema::dropIfExists('product_skus'); + } +}