<?php

namespace App\Models;

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

class PostNews extends Model
{
    //constant
    const WAITTING_FOR_APPROVAL = 0;
    CONST APPROVED = 1;
    CONST NOMAL_CONTENT = 0;
    CONST FEE_CONTENT = 1;

    CONST state_price = 1;
    CONST fluctuations_price = 2;
    CONST power_meter = 3;
    CONST person = 4;
    CONST free = 5;

    protected $table = 'post_news';
    use SoftDeletes;

    public $timestamps = true;

    protected $fillable = [
        'province',
        'district',
        'ward',
        'province_name',
        'district_name',
        'ward_name',
        'address',
        'size',
        'title',
        'description',
        'image',
        'price',
        'deposit',
        'date_available',
        'type_id',
        'user_id',
        'status',
        'amenities',
        'owner_name',
        'owner_phone',
        'email',
        'type_electric_price',
        'amount_people',
        'electricity_price',
        'type_water_price',
        'water_price',
        'water_unit',
        'electric_unit',
        'lat',
        'lng',
    ];
    protected $dates = [
        'deleted_at',
        'updated_at',
        'created_at',
    ];

    public function province()
    {
        return $this->hasOne('App\Models\Province', 'provinceid', 'province');

    }
    public function amenities()
    {
        return $this->belongsToMany(Amenity::class, 'post_amenities', 'post_id', 'amenity_id');
    }
    public function user()
    {
        return $this->belongsTo(User::class,'user_id','id');
    }
}
