ldc-crm/app/Models/SingleOptin.php
2025-07-28 09:07:54 +02:00

86 lines
2.1 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
/**
* @property integer $hashcode Hashcode.
* @property integer $brand_id Foreign key Brand.
* @property string $email Email.
* @property-read \Illuminate\Support\Carbon $created_at Created date.
* @property-read \Illuminate\Support\Carbon $updated_at Updated date.
* @property-read \App\Models\Brand $brand Brand BelongsTo relation.
* @property-read \Illuminate\Database\Eloquent\Collection<App\Models\Answer> $answers Answer morph many relation.
*/
class SingleOptin extends Model
{
use HasFactory;
/**
* The primary key for the model.
*
* @var string
*/
protected $primaryKey = 'hashcode';
/**
* The "type" of the primary key ID.
*
* @var string
*/
protected $keyType = 'uuid';
/**
* Indicates if the IDs are auto-incrementing.
*
* @var boolean
*/
public $incrementing = false;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'email',
];
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted(): void
{
static::creating(function (self $model) {
$model->hashcode = Str::uuid();
});
}
// * RELATIONS
/**
* Brand belongs to relation.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function brand(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Brand::class);
}
/**
* Answers morph to many relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function answers(): \Illuminate\Database\Eloquent\Relations\MorphToMany
{
return $this->morphToMany(Answer::class, 'model', 'model_answer', 'model_id', 'answer_id');
}
}