mein-sterntours/app/Models/LeadMail.php
2021-05-11 17:07:20 +02:00

138 lines
2.8 KiB
PHP

<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
/**
* Class LeadMail
*
* @property int $id
* @property int $lead_id
* @property int $customer_id
* @property bool $is_answer
* @property int $reply_id
* @property string $email
* @property string $recipient
* @property string $cc
* @property string $bcc
* @property string $subject
* @property string $message
* @property int $dir
* @property int $subdir
* @property bool $draft
* @property bool $important
* @property bool $send
* @property bool $fail
* @property string $error
* @property string $forward
* @property Carbon $sent_at
* @property Carbon $scheduled_at
* @property Carbon $delivered_at
* @property Carbon $created_at
* @property Carbon $updated_at
*
* @property Customer $customer
* @property Lead $lead
* @property CustomerMail $customer_mail
* @property Collection|LeadFile[] $lead_files
*
* @package App\Models
*/
class LeadMail extends Model
{
protected $table = 'lead_mails';
protected $casts = [
'lead_id' => 'int',
'customer_id' => 'int',
'is_answer' => 'bool',
'reply_id' => 'int',
'dir' => 'int',
'subdir' => 'int',
'draft' => 'bool',
'important' => 'bool',
'send' => 'bool',
'fail' => 'bool'
];
protected $dates = [
'sent_at',
'scheduled_at',
'delivered_at'
];
protected $fillable = [
'lead_id',
'customer_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'
];
public function customer()
{
return $this->belongsTo(Customer::class);
}
public function lead()
{
return $this->belongsTo(Lead::class);
}
public function lead_mail()
{
return $this->belongsTo(LeadMail::class, 'reply_id');
}
public function lead_files()
{
return $this->hasMany(LeadFile::class);
}
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();
}
}
}