89 lines
2.2 KiB
PHP
89 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\States\QrCode\QrCodeState;
|
|
use App\Tenancy\HasTenant;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Spatie\Activitylog\LogOptions;
|
|
use Spatie\Activitylog\Traits\LogsActivity;
|
|
use Spatie\ModelStates\HasStates;
|
|
|
|
class QrCode extends Model
|
|
{
|
|
use HasFactory, HasStates, HasTenant, LogsActivity;
|
|
|
|
protected $fillable = [
|
|
'tenant_id',
|
|
'serial',
|
|
'barcode_value',
|
|
'batch_id',
|
|
'status',
|
|
'replacement_for_id',
|
|
'assigned_to_household_id',
|
|
'assigned_to_user_id',
|
|
'assigned_to_store_id',
|
|
'allocated_at',
|
|
'activated_at',
|
|
'used_at',
|
|
'used_at_drop_off_id',
|
|
'scanned_by_user_id',
|
|
'expires_at',
|
|
'metadata',
|
|
'replacement_for_id',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'status' => QrCodeState::class,
|
|
'metadata' => 'array',
|
|
'allocated_at' => 'datetime',
|
|
'activated_at' => 'datetime',
|
|
'used_at' => 'datetime',
|
|
'expires_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function getRouteKeyName(): string
|
|
{
|
|
return 'serial';
|
|
}
|
|
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logOnly(['status', 'assigned_to_household_id', 'assigned_to_user_id', 'assigned_to_store_id', 'used_at_drop_off_id'])
|
|
->logOnlyDirty()
|
|
->dontSubmitEmptyLogs()
|
|
->useLogName('qr_code');
|
|
}
|
|
|
|
public function batch(): BelongsTo
|
|
{
|
|
return $this->belongsTo(QrCodeBatch::class, 'batch_id');
|
|
}
|
|
|
|
public function household(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Household::class, 'assigned_to_household_id');
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'assigned_to_user_id');
|
|
}
|
|
|
|
public function usedAtDropOff(): BelongsTo
|
|
{
|
|
return $this->belongsTo(DropOffPoint::class, 'used_at_drop_off_id');
|
|
}
|
|
|
|
public function scannedBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'scanned_by_user_id');
|
|
}
|
|
}
|