<?php
namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class Promotion
 *
 * @package App
 * @property string $plajka
 * @property string $color_picker
 * @property string $header
 * @property string $sub_header
 * @property string $description
 * @property string $image
 * @property string $residental_complex
 * @property integer $main_page_priority
 * @property integer $promotion_page_priority
 * @property-write mixed $residental_complex_id
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Promotion newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Promotion newQuery()
 * @method static \Illuminate\Database\Query\Builder|\App\Promotion onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Promotion query()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Query\Builder|\App\Promotion withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\Promotion withoutTrashed()
 * @mixin \Eloquent
 */
class Promotion extends Model
{
    use SoftDeletes;

    protected $fillable = ['plajka', 'color_picker', 'header', 'sub_header', 'description', 'image',
        'residental_complex_id', 'promotion_page_priority', 'main_page_priority', 'link'];
    protected $hidden = [];

    /**
     * Set to null if empty
     * @param $input
     */
    public function setResidentalComplexIdAttribute($input)
    {
        $this->attributes['residental_complex_id'] = $input ? $input : null;
    }
    
    public function residental_complex()
    {
        return $this->belongsTo(ResidentialComplex::class, 'residental_complex_id')->withTrashed();
    }
    
}
