init
This commit is contained in:
232 files changed
+25416
No files matched your search
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\BazaarPurchaseFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable(['mobile_app_id', 'product_id', 'purchase_token', 'purchase_token_hash', 'status', 'is_consumed', 'purchased_at', 'validated_at', 'bazaar_response'])]
|
||||
#[Hidden(['purchase_token', 'purchase_token_hash'])]
|
||||
class BazaarPurchase extends Model
|
||||
{
|
||||
/** @use HasFactory<BazaarPurchaseFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected $attributes = ['status' => 'unknown'];
|
||||
|
||||
public function mobileApp(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(MobileApp::class);
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saving(function (BazaarPurchase $purchase): void {
|
||||
if ($purchase->isDirty('purchase_token')) {
|
||||
$purchase->purchase_token_hash = hash('sha256', $purchase->purchase_token);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_consumed' => 'boolean',
|
||||
'purchase_token' => 'encrypted',
|
||||
'purchased_at' => 'datetime',
|
||||
'validated_at' => 'datetime',
|
||||
'bazaar_response' => 'array',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user