add reward and cascadesofdelete lib
parent
63d746652a
commit
3b139e25f8
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
class CoinReward extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'amount_buy',
|
||||
'bonus_coin',
|
||||
'customer_level_id',
|
||||
];
|
||||
}
|
@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -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…
Reference in New Issue