<?php

class BudgetRefrence extends \Eloquent {

	use SoftDeletingTrait;

	protected $guarded		 = array();

	public function budgetCostsRequests() {
		return $this->belongsTo('BudgetCostsRequests', 'request_id');
	}

	public function budgetCostsRequestsNotification() {
		return $this->hasMany('BudgetCostsRequestsNotification');
	}
	
	// отметка о просмотре уведомления
	public function setNotificationViewed() {
		$costsRequestNotifications = BudgetCostsRequestsNotification::whereBudgetRefrenceId($this->id)
																																->get();
		if($costsRequestNotifications){
			foreach ($costsRequestNotifications as $costsRequestNotification){
				$costsRequestNotification->is_viewed = 1;
				$costsRequestNotification->save();
			}
		}
	}
	
}
