add reward and cascadesofdelete lib

dev
Aji Kamaludin 1 year ago
parent 63d746652a
commit 3b139e25f8
No known key found for this signature in database
GPG Key ID: 19058F67F0083AD3

@ -12,4 +12,9 @@ class CoinHistory extends Model
'related_type',
'related_id',
];
public function customer()
{
return $this->belongsTo(Customer::class);
}
}

@ -0,0 +1,13 @@
<?php
namespace App\Models;
class CoinReward extends Model
{
protected $fillable = [
'amount_buy',
'bonus_coin',
'customer_level_id',
];
}

@ -2,8 +2,17 @@
namespace App\Models;
class Customer extends Model
use App\Models\Traits\UserTrackable;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Customer extends Authenticatable
{
use HasFactory, HasUlids, UserTrackable, SoftDeletes;
protected $fillable = [
'email',
'password',

@ -2,8 +2,8 @@
namespace App\Models;
use App\Models\Traits\CascadeSoftDeletes;
use App\Models\Traits\UserTrackable;
use Dyrynda\Database\Support\CascadeSoftDeletes;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model as BaseModel;
@ -14,4 +14,6 @@ class Model extends BaseModel
use HasFactory, HasUlids, UserTrackable, SoftDeletes, CascadeSoftDeletes;
public $cascadeDeletes = [];
protected $dates = ['deleted_at'];
}

@ -1,21 +0,0 @@
<?php
namespace App\Models\Traits;
trait CascadeSoftDeletes
{
protected static function bootCascadeSoftDeletes()
{
static::deleting(function ($resource) {
foreach ($resource->cascadeDeletes as $relation) {
$resource->{$relation}()->delete();
}
});
static::restoring(function ($resource) {
foreach ($resource->cascadeDeletes as $relation) {
$resource->{$relation}()->withTrashed()->restore();
}
});
}
}

@ -18,4 +18,9 @@ class Voucher extends Model
'comment',
'expired',
];
public function location()
{
return $this->belongsTo(Location::class);
}
}

@ -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",

48
composer.lock generated

@ -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",

@ -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',

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('coin_rewards', function (Blueprint $table) {
$table->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');
}
};
Loading…
Cancel
Save