<?php namespace App;

use Illuminate\Database\Eloquent\Model;

class Auction extends Model
{

	protected $fillable
		= [
			'product_id',
			'amount',
			'startprice',
			'minraise',
			'buynow',
			'enddate',
			'disabled'
		];

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

	public function bestBid()
	{
		$bid = $this->bids()->orderBy('id', 'desc')->first();
		if ($bid == null) {
			return $this->startprice;
		} else {
			return $bid->bid;
		}
	}
	public function product(){
		return $this->belongsTo('App\Product');
	}

}
