2020-12-01 17:02:10 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2023-06-26 15:10:28 +02:00
|
|
|
use Illuminate\Support\Str;
|
2020-12-01 17:02:10 +01:00
|
|
|
|
2023-09-06 17:24:53 +02:00
|
|
|
/**
|
2025-07-23 14:24:38 +02:00
|
|
|
* @property integer $hashcode Hashcode.
|
|
|
|
|
* @property integer $brand_id Foreign key Brand.
|
|
|
|
|
* @property string $email Email.
|
2023-09-06 17:24:53 +02:00
|
|
|
* @property-read \Illuminate\Support\Carbon $created_at Created date.
|
|
|
|
|
* @property-read \Illuminate\Support\Carbon $updated_at Updated date.
|
|
|
|
|
|
2025-07-23 14:24:38 +02:00
|
|
|
* @property-read \App\Models\Brand $brand Brand BelongsTo relation.
|
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<App\Models\Answer> $answers Answer morph many relation.
|
2023-09-06 17:24:53 +02:00
|
|
|
*/
|
2020-12-02 10:08:27 +01:00
|
|
|
class SingleOptin extends Model
|
2020-12-01 17:02:10 +01:00
|
|
|
{
|
|
|
|
|
use HasFactory;
|
|
|
|
|
|
2023-06-26 15:10:28 +02:00
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
|
*
|
2025-07-24 11:32:12 +02:00
|
|
|
* @var array<int, string>
|
2021-12-19 15:57:24 +01:00
|
|
|
*/
|
2021-03-14 10:45:42 +01:00
|
|
|
protected $fillable = [
|
2023-09-04 13:08:34 +02:00
|
|
|
'email',
|
2021-03-14 10:45:42 +01:00
|
|
|
];
|
|
|
|
|
|
2023-06-26 15:10:28 +02:00
|
|
|
/**
|
|
|
|
|
* Perform any actions required after the model boots.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2023-09-06 17:24:53 +02:00
|
|
|
protected static function booted(): void
|
2023-06-26 15:10:28 +02:00
|
|
|
{
|
|
|
|
|
static::creating(function (self $model) {
|
|
|
|
|
$model->hashcode = Str::uuid();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
// * RELATIONS
|
|
|
|
|
|
2021-02-28 12:04:49 +01:00
|
|
|
/**
|
2025-07-24 11:32:12 +02:00
|
|
|
* Brand belongs to relation.
|
2021-02-28 12:04:49 +01:00
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
*/
|
2023-09-06 17:24:53 +02:00
|
|
|
public function brand(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2021-02-28 12:04:49 +01:00
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Brand::class);
|
2020-12-01 17:02:10 +01:00
|
|
|
}
|
2025-07-23 14:24:38 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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');
|
|
|
|
|
}
|
2020-12-01 17:02:10 +01:00
|
|
|
}
|