You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.6 KiB

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Str;
class SignupChannel extends Model
{
use HasFactory;
public const STATUS_ENABLED = 'enabled';
public const STATUS_DISABLED = 'disabled';
public const STATUSES = [
self::STATUS_ENABLED,
self::STATUS_DISABLED,
];
protected $fillable = [
'competition_id',
'channel_name',
'status',
'shared_secret',
'success_callback_url',
'remark',
];
protected $hidden = [
'shared_secret',
];
protected static function booted(): void
{
static::creating(function (SignupChannel $channel): void {
if ($channel->channel_code !== null && $channel->channel_code !== '') {
return;
}
do {
$channel->channel_code = (string) Str::ulid();
} while (static::query()->where('channel_code', $channel->channel_code)->exists());
});
}
public function competition(): BelongsTo
{
return $this->belongsTo(Competition::class);
}
public function firstSourceUsers(): HasMany
{
return $this->hasMany(User::class, 'first_channel_id');
}
public function lastSourceUsers(): HasMany
{
return $this->hasMany(User::class, 'last_channel_id');
}
public function applications(): HasMany
{
return $this->hasMany(Application::class, 'signup_channel_id');
}
}