From 3b139e25f8eeb575e16fe40fb27340ed9b7b4808 Mon Sep 17 00:00:00 2001 From: Aji Kamaludin Date: Wed, 24 May 2023 21:59:15 +0700 Subject: [PATCH] add reward and cascadesofdelete lib --- app/Models/CoinHistory.php | 5 ++ app/Models/CoinReward.php | 13 +++++ app/Models/Customer.php | 11 ++++- app/Models/Model.php | 4 +- app/Models/Traits/CascadeSoftDeletes.php | 21 -------- app/Models/Voucher.php | 5 ++ composer.json | 1 + composer.lock | 48 ++++++++++++++++++- config/auth.php | 9 ++++ ...05_24_145103_create_coin_rewards_table.php | 36 ++++++++++++++ 10 files changed, 129 insertions(+), 24 deletions(-) create mode 100644 app/Models/CoinReward.php delete mode 100644 app/Models/Traits/CascadeSoftDeletes.php create mode 100644 database/migrations/2023_05_24_145103_create_coin_rewards_table.php diff --git a/app/Models/CoinHistory.php b/app/Models/CoinHistory.php index 3cbf428..2d3c739 100644 --- a/app/Models/CoinHistory.php +++ b/app/Models/CoinHistory.php @@ -12,4 +12,9 @@ class CoinHistory extends Model 'related_type', 'related_id', ]; + + public function customer() + { + return $this->belongsTo(Customer::class); + } } diff --git a/app/Models/CoinReward.php b/app/Models/CoinReward.php new file mode 100644 index 0000000..828babc --- /dev/null +++ b/app/Models/CoinReward.php @@ -0,0 +1,13 @@ +cascadeDeletes as $relation) { - $resource->{$relation}()->delete(); - } - }); - - static::restoring(function ($resource) { - foreach ($resource->cascadeDeletes as $relation) { - $resource->{$relation}()->withTrashed()->restore(); - } - }); - } -} diff --git a/app/Models/Voucher.php b/app/Models/Voucher.php index 966cc22..04ae0dd 100644 --- a/app/Models/Voucher.php +++ b/app/Models/Voucher.php @@ -18,4 +18,9 @@ class Voucher extends Model 'comment', 'expired', ]; + + public function location() + { + return $this->belongsTo(Location::class); + } } diff --git a/composer.json b/composer.json index b211927..ac44586 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,7 @@ "license": "MIT", "require": { "php": "^8.1.0", + "dyrynda/laravel-cascade-soft-deletes": "^4.3", "guzzlehttp/guzzle": "^7.7.0", "inertiajs/inertia-laravel": "^0.6.9", "laravel/framework": "^10.12.0", diff --git a/composer.lock b/composer.lock index ec05cda..eb8dde7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b2fc21d50fd63d0fa1335a3c5b384ce8", + "content-hash": "bbaa3598d623d97e943f37916ee4e35e", "packages": [ { "name": "brick/math", @@ -365,6 +365,52 @@ ], "time": "2022-09-10T18:51:20+00:00" }, + { + "name": "dyrynda/laravel-cascade-soft-deletes", + "version": "4.3.0", + "source": { + "type": "git", + "url": "https://github.com/michaeldyrynda/laravel-cascade-soft-deletes.git", + "reference": "a857578df3880f34fc9ed9b52369adbb251f12d2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/michaeldyrynda/laravel-cascade-soft-deletes/zipball/a857578df3880f34fc9ed9b52369adbb251f12d2", + "reference": "a857578df3880f34fc9ed9b52369adbb251f12d2", + "shasum": "" + }, + "require": { + "illuminate/database": "^10.0", + "illuminate/events": "^10.0", + "php": "^8.1" + }, + "require-dev": { + "phpunit/phpunit": "^9.6 || ^10.0" + }, + "type": "utility", + "autoload": { + "psr-4": { + "Dyrynda\\Database\\Support\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dyrynda", + "email": "michael@dyrynda.com.au", + "homepage": "https://dyrynda.com.au" + } + ], + "description": "Cascading deletes for Eloquent models that implement soft deletes", + "support": { + "issues": "https://github.com/michaeldyrynda/laravel-cascade-soft-deletes/issues", + "source": "https://github.com/michaeldyrynda/laravel-cascade-soft-deletes/tree/4.3.0" + }, + "time": "2023-02-16T01:47:23+00:00" + }, { "name": "egulias/email-validator", "version": "4.0.1", diff --git a/config/auth.php b/config/auth.php index d8c6cee..43444c6 100644 --- a/config/auth.php +++ b/config/auth.php @@ -40,6 +40,10 @@ return [ 'driver' => 'session', 'provider' => 'users', ], + 'customer' => [ + 'driver' => 'session', + 'provider' => 'customers' + ] ], /* @@ -65,6 +69,11 @@ return [ 'model' => App\Models\User::class, ], + 'customers' => [ + 'driver' => 'eloquent', + 'model' => App\Models\Customer::class, + ], + // 'users' => [ // 'driver' => 'database', // 'table' => 'users', diff --git a/database/migrations/2023_05_24_145103_create_coin_rewards_table.php b/database/migrations/2023_05_24_145103_create_coin_rewards_table.php new file mode 100644 index 0000000..8656cbd --- /dev/null +++ b/database/migrations/2023_05_24_145103_create_coin_rewards_table.php @@ -0,0 +1,36 @@ +ulid('id')->primary(); + + $table->decimal('amount_buy', 20, 2)->default(0); + $table->decimal('bonus_coin', 20, 2)->default(0); + $table->ulid('customer_level_id')->nullable(); + + $table->timestamps(); + $table->softDeletes(); + $table->ulid('created_by')->nullable(); + $table->ulid('updated_by')->nullable(); + $table->ulid('deleted_by')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('coin_rewards'); + } +};