Add Campaigns module for grouping QR codes.
Deploy Ladill QR Plus / deploy (push) Successful in 1m6s

Let accounts organise codes by promo or launch, attach or detach codes, and view combined scan totals from the sidebar.
This commit is contained in:
isaacclad
2026-07-16 20:43:02 +00:00
parent ccb7c971e6
commit 95d73d1367
13 changed files with 699 additions and 1 deletions
+81
View File
@@ -0,0 +1,81 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Campaign extends Model
{
public const STATUS_DRAFT = 'draft';
public const STATUS_ACTIVE = 'active';
public const STATUS_ARCHIVED = 'archived';
public const STATUSES = [
self::STATUS_DRAFT => 'Draft',
self::STATUS_ACTIVE => 'Active',
self::STATUS_ARCHIVED => 'Archived',
];
protected $fillable = [
'user_id',
'name',
'description',
'status',
'starts_at',
'ends_at',
];
protected function casts(): array
{
return [
'starts_at' => 'datetime',
'ends_at' => 'datetime',
];
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function qrCodes(): HasMany
{
return $this->hasMany(QrCode::class);
}
public function statusLabel(): string
{
return self::STATUSES[$this->status] ?? ucfirst((string) $this->status);
}
public function isLive(): bool
{
if ($this->status !== self::STATUS_ACTIVE) {
return false;
}
if ($this->starts_at && $this->starts_at->isFuture()) {
return false;
}
if ($this->ends_at && $this->ends_at->isPast()) {
return false;
}
return true;
}
public function totalScans(): int
{
return (int) $this->qrCodes()->sum('scans_total');
}
public function codesCount(): int
{
return (int) $this->qrCodes()->count();
}
}
+6
View File
@@ -30,6 +30,7 @@ class QrCode extends Model
protected $fillable = [
'user_id',
'campaign_id',
'short_code',
'type',
'label',
@@ -59,6 +60,11 @@ class QrCode extends Model
return $this->belongsTo(User::class);
}
public function campaign(): BelongsTo
{
return $this->belongsTo(Campaign::class);
}
public function document(): BelongsTo
{
return $this->belongsTo(QrDocument::class, 'qr_document_id');
+5
View File
@@ -58,6 +58,11 @@ class User extends Authenticatable
return $this->hasMany(QrCode::class);
}
public function campaigns(): HasMany
{
return $this->hasMany(Campaign::class);
}
public function qrSetting(): HasOne
{
return $this->hasOne(QrSetting::class);