mein-sterntours/app/Models/CustomerMail.php
2020-03-26 09:48:19 +01:00

120 lines
2.4 KiB
PHP

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