'int', 'travel_user_id' => 'int', 'is_answer' => 'bool', 'reply_id' => 'int', 'dir' => 'int', 'subdir' => 'int', 'draft' => 'bool', 'important' => 'bool', 'send' => 'bool', 'fail' => 'bool', 'recipient' => 'array', 'forward' => 'array', 'cc' => 'array', 'bcc' => 'array', 'sent_at' => 'datetime', 'scheduled_at' => 'datetime', 'delivered_at' => 'datetime', 'deleted_at' => 'datetime', ]; protected $fillable = [ 'travel_user_booking_fewo_id', 'travel_user_id', 'is_answer', 'reply_id', 'email', 'recipient', 'cc', 'bcc', 'subject', 'message', 'dir', 'subdir', 'draft', 'important', 'send', 'fail', 'error', 'forward', 'sent_at', 'scheduled_at', 'delivered_at' ]; protected static function boot() { parent::boot(); static::deleting(function($model) { foreach ($model->customer_fewo_files as $relation) { $relation->delete(); } }); } public function customer_fewo_mail() { return $this->belongsTo(CustomerFewoMail::class, 'reply_id'); } public function customer_mail() { return $this->belongsTo(CustomerFewoMail::class, 'reply_id'); } public function travel_user_booking_fewo() { return $this->belongsTo(TravelUserBookingFewo::class); } public function booking() { return $this->belongsTo(TravelUserBookingFewo::class, 'travel_user_booking_fewo_id'); } public function travel_user() { return $this->belongsTo(TravelUser::class); } public function customer() { return $this->belongsTo(TravelUser::class, 'travel_user_id'); } public function customer_fewo_files() { return $this->hasMany(CustomerFewoFile::class); } public function customer_files() { return $this->hasMany(CustomerFewoFile::class, 'customer_fewo_mail_id'); } public function customer_fewo_mails() { return $this->hasMany(CustomerFewoMail::class, 'reply_id'); } public function getSentAtRaw(){ return $this->attributes['sent_at']; } public function getSentAtAttribute(){ if(!$this->attributes['sent_at']){ return ""; } return Carbon::parse($this->attributes['sent_at'])->format(\Util::formatDateTimeDB()); } public function getCreatedAtAttribute(){ if(!$this->attributes['created_at']){ return ""; } return Carbon::parse($this->attributes['created_at'])->format(\Util::formatDateTimeDB()); } public function setForwardMessage($forward = []) { if($forward && is_array($forward)){ if(isset($this->forward) && $this->forward){ $this->forward = array_merge($this->forward , $forward); }else{ $this->forward = $forward; } $this->save(); } } }