firefly-iii/app/models/PiggybankRepetition.php

54 lines
1.2 KiB
PHP
Raw Normal View History

<?php
use Carbon\Carbon;
2014-12-06 05:12:55 -06:00
use Illuminate\Database\Eloquent\Builder;
use Watson\Validating\ValidatingTrait;
2014-12-20 08:00:53 -06:00
use \Illuminate\Database\Eloquent\Model as Eloquent;
2014-12-13 14:59:02 -06:00
/**
* Class PiggyBankRepetition
2014-12-13 14:59:02 -06:00
*/
class PiggyBankRepetition extends Eloquent
{
2014-12-06 05:12:55 -06:00
use ValidatingTrait;
public static $rules
2014-11-18 02:47:50 -06:00
= [
'piggy_bank_id' => 'required|exists:piggy_banks,id',
2014-11-18 02:47:50 -06:00
'targetdate' => 'date',
'startdate' => 'date',
'currentamount' => 'required|numeric'];
/**
* @return array
*/
public function getDates()
{
return ['created_at', 'updated_at', 'targetdate', 'startdate'];
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function piggyBank()
{
return $this->belongsTo('PiggyBank');
}
2014-12-13 14:59:02 -06:00
/**
* @param Builder $query
* @param Carbon $date
*/
2014-12-06 05:12:55 -06:00
public function scopeStarts(Builder $query, Carbon $date)
{
$query->where('startdate', $date->format('Y-m-d'));
}
2014-12-06 05:12:55 -06:00
2014-12-13 14:59:02 -06:00
/**
* @param Builder $query
* @param Carbon $date
*/
2014-12-06 05:12:55 -06:00
public function scopeTargets(Builder $query, Carbon $date)
{
$query->where('targetdate', $date->format('Y-m-d'));
}
}