VCard.php 2.05 KB
<?php

namespace App\Models;

use App\Models\Pivots\GoalAdvertisement;
use App\Models\Pivots\GoalVCard;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Collection;

class VCard extends Model
{
    use SoftDeletes;

    protected $table = 'v_cards';

    protected $fillable = [
        'external_id',
        'campaign_external_id',
        'campaign_id',
        'country',
        'city',
        'work_time',
        'phone',
        'street',
        'house',
        'building',
        'apartment',
        'instant_messenger',
        'company_name',
        'extra_message',
        'contact_email',
        'ogrn',
        'metro_station_id',
        'point_on_map',
        'contact_person',
        'reserve_delete_at',
    ];

    protected $casts = [
        'phone' => 'json',
        'instant_messenger' => 'json',
        'point_on_map' => 'json',
        'reserve_delete_at' => 'datetime',
    ];

    /**
     * @return Collection
     */
    static public function getPropertiesWatch()
    {
        return collect([
            'country',
            'city',
            'work_time',
            'phone',
            'street',
            'house',
            'building',
            'apartment',
            'instant_messenger',
            'company_name',
            'extra_message',
            'contact_email',
            'ogrn',
            'metro_station_id',
            'point_on_map',
            'contact_person',
        ]);
    }

    /**
     * @param Builder $query
     * @return Builder
     */
    public function scopeForNotReserveDelete($query)
    {
        return $query->whereNull('reserve_delete_at');
    }

    public function goalVCards()
    {
        return $this->hasMany(GoalVCard::class, 'v_card_id');
    }

    public function goalAdvertisements()
    {
        return $this->hasMany(GoalAdvertisement::class, 'v_card_id');
    }

    public function errors()
    {
        return $this->morphMany(YandexError::class, 'cause');
    }

}