<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Job extends Model
{
	protected $table = 'jobs';

	protected $dates = ['created_at','updated_at','expires_at'];

	public function jobCategory(){
		return $this->belongsTo('App\JobCategory');
	}

	public function company(){
		return $this->belongsTo('App\Company');
	}

	public function applications(){
		return $this->hasMany('App\JobApplication');
	}

	public function expiryStatus(){
		$status = $this->expires_at->diffForHumans();
		if($this->expires_at<\Carbon\Carbon::now()){
			$status = "Expired";
		}
		return $status;
	}

	public function hasExpired(){
		$status = $this->expires_at->diffForHumans();
		return $this->expires_at<\Carbon\Carbon::now();
	}
}
