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