feat(point record): membuat model, migrasi dan enum untuk poin record
This commit is contained in:
parent
422e4d876f
commit
2a4e07c7c0
30
app/Enums/PointRecordType.php
Normal file
30
app/Enums/PointRecordType.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Traits\WithCommentEnum;
|
||||
use App\Traits\WithValueEnum;
|
||||
|
||||
enum PointRecordType: int
|
||||
{
|
||||
use WithCommentEnum, WithValueEnum;
|
||||
|
||||
case TIER = 1;
|
||||
case REWARD = 2;
|
||||
|
||||
public function label()
|
||||
{
|
||||
return match ($this) {
|
||||
self::TIER => 'Tier',
|
||||
self::REWARD => 'Hadiah',
|
||||
};
|
||||
}
|
||||
|
||||
public function color()
|
||||
{
|
||||
return match ($this) {
|
||||
self::TIER => 'emerald',
|
||||
self::REWARD => 'blue',
|
||||
};
|
||||
}
|
||||
}
|
||||
29
app/Models/PointRecord.php
Normal file
29
app/Models/PointRecord.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\PointRecordType;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class PointRecord extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'change' => 'int',
|
||||
'type' => PointRecordType::class,
|
||||
'is_addition' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\PointRecordType;
|
||||
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('point_records', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->unsignedBigInteger('change');
|
||||
$table->enum('type', [PointRecordType::values()])->comment(PointRecordType::comment());
|
||||
$table->string('description', 50);
|
||||
$table->boolean('is_addition');
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
$table->timestamp('updated_at')->nullable()->useCurrentOnUpdate();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('point_records');
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user