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.
60 lines
1.3 KiB
60 lines
1.3 KiB
|
1 month ago
|
<?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;
|
||
|
|
|
||
|
|
class FormSchemaDefinition extends Model
|
||
|
|
{
|
||
|
|
use HasFactory;
|
||
|
|
|
||
|
|
public const PURPOSE_SIGNUP = 'signup';
|
||
|
|
|
||
|
|
public const PURPOSE_REVIEW = 'review';
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'competition_id',
|
||
|
|
'purpose',
|
||
|
|
'name',
|
||
|
|
'version',
|
||
|
|
'schema_json',
|
||
|
|
'is_published',
|
||
|
|
];
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @var array<string, string>
|
||
|
|
*/
|
||
|
|
protected $casts = [
|
||
|
|
'schema_json' => 'array',
|
||
|
|
'is_published' => 'boolean',
|
||
|
|
];
|
||
|
|
|
||
|
|
public function competition(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Competition::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function competitionsUsingAsForm(): HasMany
|
||
|
|
{
|
||
|
|
return $this->hasMany(Competition::class, 'form_schema_id');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function competitionsUsingAsReview(): HasMany
|
||
|
|
{
|
||
|
|
return $this->hasMany(Competition::class, 'review_form_schema_id');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function scopeSignup($query)
|
||
|
|
{
|
||
|
|
return $query->where('purpose', self::PURPOSE_SIGNUP);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function scopeReview($query)
|
||
|
|
{
|
||
|
|
return $query->where('purpose', self::PURPOSE_REVIEW);
|
||
|
|
}
|
||
|
|
}
|