$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 */ 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'); } }